Title: Operating System Principles
1Operating SystemPrinciples
- Ku-Yaw Chang
- canseco_at_mail.dyu.edu.tw
- Assistant Professor, Department of Computer
Science and Information Engineering - Da-Yeh University
2Chapter 2 System Structures
- An operating system can be viewed from different
vantage points - Services that the system provides
- Programmers
- Interface available to users and programmers
- Users
- Components and their connections
- Operating system designer
3Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
42.1 Operating-System Services
- Common services (1/2)
- User interfaces
- Command-line interface (CLI)
- Batch interface
- Graphical user interface (GUI)
- Program execution
- to load a program into memory and to run it.
- I/O operations
- user programs cannot execute I/O operations
directly
52.1 Operating-System Services
- Common services (1/2)
- File-system manipulation
- capability to read, write, create, and delete
files - Communications
- exchange of information between processes
- Implemented via shared memory or message passing
- Error detection
- ensure correct computing by detecting errors in
the CPU and memory hardware, in I/O devices, or
in user programs
6Additional Functions
- Not for helping the user, but rather for ensuring
efficient system operations - Resource allocation
- allocate resources to multiple users or multiple
jobs running at the same time - Accounting
- keep track of and record which users use how much
and what kinds of computer resources for account
billing or for accumulating usage statistics - Protection and security
- ensure that all access to system resources is
controlled - each user authenticate himself or herself to the
system
7Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
8User Operating-System Interface
- Two approaches for users to interact with OS
- Command-line interface (CLI) or command
interpreter - Graphical user interface (GUI)
92.2.1 Command Interpreter
- Command interpreter
- Included in the OS kernel
- Treated as a special program
- Windows XP and UNIX
- Also known as shells
- Multiple command interpreters to choose from
- On UNIX and Linux systems
- Bourne shell
- C shell
- See what was my login shell?
- saturn echo SHELL
- /bin/csh
- Bourne-Again shell
- Korn shell
102.2.1 Command Interpreter
- Main function
- To get and execute the next user-specified
command - Example file manipulation
- create, delete, list, print, copy, execute
- Internal vs. external command
- Internal
- The command interpreter contains the code to
execute the command - External
- Use the command to identify a file to be loaded
into memory and executed
112.2.2 Graphical User Interfaces
- User-friendly desktop metaphor interface
- A mouse-based window-and-menu system
- Usually mouse, keyboard, and monitor
- Icons represent files, programs, actions, etc
- Various mouse buttons over objects in the
interface cause various actions (provide
information, options, execute function, open
directory (known as a folder) - Invented at Xerox PARC
122.2.2 Graphical User Interfaces
- Many systems now include both CLI and GUI
interfaces - Microsoft Windows is GUI with CLI command shell
- command.com or cmd.exe
- Apple Mac OS X as Aqua GUI interface with UNIX
kernel underneath and shells available - Solaris is CLI with optional GUI interfaces (Java
Desktop, KDE)
13Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
142.3 System Calls
- The interface between a process and the OS
- Assembly-language
- Higher-level language
- C, C and Perl
- Mostly accessed by programs via a high-level
Application Program Interface (API) rather than
direct system call use - Win32 API for Windows
- POSIX API for POSIX-based systems (including
virtually all versions of UNIX, Linux, and Mac OS
X) - Java API for the Java virtual machine (JVM)
152.3 System Calls
- Why use APIs rather than system calls?
- Better program portability
- Easy to work with
16Depiction of XP Architecture
17Different Types of I/O
- Low-level I/O (system call)
- _open, _close
- _read, _write
- Stream I/O
- fopen, fclose
- fread, fwrite
- WIN32 API
- CreateFile, CloseHandle
- ReadFile, WriteFile
18Example of Standard API
- Consider the ReadFile() function in the Win32 API
- a function for reading from a file
- A description of the parameters passed to
ReadFile() - HANDLE filethe file to be read
- LPVOID buffera buffer where the data will be
read into and written from - DWORD bytesToReadthe number of bytes to be read
into the buffer - LPDWORD bytesReadthe number of bytes read during
the last read - LPOVERLAPPED ovlindicates if overlapped I/O is
being used
192.3 System Calls
- Even simple programs may make heavy use of the
operating system. - To read data from one file and to copy them to
another file - Requiring a sequence of system calls
- Details are hidden from the programmer
20System Call Sequence
21System Call Implementation
- Typically, a number associated with each system
call - System-call interface maintains a table indexed
according to these numbers - The system call interface invokes intended system
call in OS kernel and returns status of the
system call and any return values - The caller need know nothing about how the system
call is implemented - Just needs to obey API and understand what OS
will do as a result call - Most details of OS interface hidden from
programmer by API - Managed by run-time support library (set of
functions built into libraries included with
compiler)
22The Handling of open() System Call
23Standard C Library Example
- C program invoking printf() library call, which
calls write() system call
24System Call Parameter Passing
- Three general methods used to pass parameters to
the OS - Simplest pass the parameters in registers
- In some cases, may be more parameters than
registers - Parameters stored in a block, or table, in
memory, and address of block passed as a
parameter in a register - This approach taken by Linux and Solaris
- Parameters placed, or pushed, onto the stack by
the program and popped off the stack by the
operating system - Block and stack methods do not limit the number
or length of parameters being passed
25Parameter Passing via Table
26Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
272.4 Types of System Calls
- Five major categories
- Process control
- File management
- Device management
- Information maintenance
- Communications
282.4.1 Process Control
- A running program
- Halt its execution
- normally (end)
- abnormally (abort)
- A dump of memory
- Load and execute another program
- fork()
- exec()
29MS-DOS
At System Start-up
Running a Program
30FreeBSD running multiple programs
312.4.5 Communication
- Two common models
- Message-passing
- Messages can be exchanged either directly or
indirectly through a common mailbox - A connection must be established
- open, connection, close
- Useful for smaller amounts of data
- Easier for intercomputer communication
- Shared-memory
- Create and gain access to regions of memory owned
by other processes - Maximum speed and convenience
322.4.5 Communication
Message Passing
Shared Memory
33Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
342.5 System Programs
- System programs provide a convenient environment
for program development and execution - File management
- Status information
- File modification
- Programming language support
- Program loading and execution
- Communication
- System utilities or application programs
- To solve common problems, or perform common
operations - Web browsers and word processors
- Games
352.5 System Programs
- Command interpreter
- The most important system program
- Two approaches
- The command interpreter contains the code to
execute the command. - Internal command
- Implement most commands by system programs
- External command
36Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
372.6.1 Design Goals
- User goals
- should be convenient to use, easy to learn,
reliable, safe, and fast - System goals
- should be easy to design, implement, and
maintain, as well as flexible, reliable,
error-free, and efficient
382.6.2 Mechanisms and Policies
- General software engineering principles are
applicable to operating systems - Separation of policy from mechanism
- For flexibility
- Mechanisms
- How to do something
- A general mechanism
- Policies
- What will be done
- Change across places or over time
392.6.2 Mechanisms and Policies
- Microkernel-based
- Take the separation of mechanism and policy to
one extreme - Windows / Apple Macintosh (Mac OS X)
- Both mechanism and policy are encoded in the
system
402.6.3 Implementation
- Traditionally written in assembly language,
operating systems can now be written in
higher-level languages such as C/C - Linux and Windows XP are written mostly in C
- Code written in a high-level language
- can be written faster
- more compact
- easier to understand and debug
- easier to port (move to some other hardware)
- Disadvantage
- Reduced speed and increased storage requirements
41Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
422.7 Operating-System Structure
- To partition the task (OS) into small components
(modules) - Not one monolithic system
- Available approaches
- Simple structure
- Layered approach
- Microkernels
- Modules
432.7.1 Simple Structure
- MS-DOS
- written to provide the most functionality in the
least space - not divided into modules
- Although having some structure, its interfaces
and levels of functionality are not well separated
44MS-DOS Layer Structure
452.7.1 Simple Structure
- UNIX (original)
- consists of two separable parts
- Kernel
- everything below the system-call interface and
above the physical hardware - System programs
46Unix System Structure
472.7.2 Layered Approach
- OS is broken into a number of layers (or levels)
- Each built on top of lower layers
- The bottom layer (layer 0) is the hardware
- The highest layer (layer N) is the user interface
- With modularity, layers are selected such that
each uses functions (operations) and services of
only lower-level layers. - Simplify debugging and system verification
- Difficult to define each layer
- Less efficient overhead
48A Layered OS
49An OS layer
50OS/2 layer structure
51Windows NT
- First release
- A highly layer-oriented organization
- Low performance (compared to Windows 95)
- NT 4.0
- Move layers from user space to kernel space
- Closely integration
522.7.3 Microkernels
- Mach
- Developed at Carnegie Mellon University in the
mid-1980s - Use the microkernel approach
- Removing non-essential components from the kernel
- Implement them as system- and user-level programs
- A smaller kernel
- Main function
- To provide a communication facility
532.7.3 Microkernels
- Benefits
- easier to extend
- easier to port
- more security
- more reliability
- Examples
- Tru64 UNIX UNIX Mach kernel
- MacOS X based on Mach kernel
- QNX a real-time OS
- Windows NT ( a hybrid structure)
54Windows NT client-server structure
552.7.4 Modules
- Most modern operating systems implement kernel
modules - Uses object-oriented approach
- Each core component is separate
- Each talks to the others over known interfaces
- Each is loadable as needed within the kernel
- Overall, similar to layers but with more flexible
56Solaris Loadable Modules
57Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
582.8 Virtual Machines
- A computer system is made up of layers
- Hardware is the lowest
- Virtual machines
- take the layered approach to its logical
conclusion - treat hardware and the operating system kernel as
though they were all hardware - provide an interface identical to the underlying
bare hardware - OS creates the illusion of multiple processes
- each has on its own processor with its own
(virtual) memory
59System Models
Non-virtual Machine
Virtual Machine
602.8.1 Implementation
- Difficult to implement
- To provide an exact duplicate of the underlying
machine - User mode
- Monitor mode
- Time the major difference
- I/O
- Less time or more time
- CPU
- Multiprogrammed among many virtual machines
612.8.2 Benefits
- Provide complete protection of system resources
- Each virtual machine is isolated from all other
virtual machines. - Permits no direct sharing of resources
- A perfect vehicle for operating-systems research
and development - System development is done on the virtual
machine, instead of on a physical machine and so
does not disrupt normal system operation - Solve system compatibility problems
622.8.3 Examples
- 2.8.3.1 VMware
- a popular commercial application
- abstract Intel 80X86 hardware
- run several guest operating systems concurrently
63VMware Architecture
642.8.3.2 Java Virtual Machine
- A very popular object-oriented language
- By Sun Microsystems in late 1995
- Consists of
- A language specification
- A large API library
- A specification for a Java virtual machine (JVM)
- A class loader
- A class verifier
- A Java interpreter
652.8.3.2 Java Virtual Machine
- A Java program consists of one or more classes.
- For each class, the Java compiler produce an
architecture-neutral bytecode output (.class)
file - Run on any implementation of the JVM
66Java virtual machine
672.8.3.2 Java Virtual Machine
- Garbage collection
- Reclaim memory from objects no longer in use and
return it to the system - Just-in-time (JIT) compiler
- The first time a Java method is invoked, the
bytecodes are turned into native machine language
for the host computer - These operations are cached for later use
68Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
692.9 Operating System Generation
- Operating systems are designed to run on any of a
class of machines - must be configured for each specific computer
site. - System generation (SYSGEN)
- obtain information concerning the specific
configuration of the hardware system. - from a given file
- ask the operator
- probe the hardware directly
70Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
712.10 System Boot
- Booting
- starting a computer by loading the kernel
- Bootstrap program (bootstrap loader)
- code stored in ROM that is able to locate the
kernel, load it into memory, and start its
execution - two-step process
- A simple bootstrap loader fetches a more complex
boot program from disk
72Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
73Summary
74Chapter 2 Computer System Structures
- Operating-System Services
- User Operating-System Interface
- System Calls
- Types of System Calls
- System Programs
- Operating-System Design and Implementation
- Operating-System Structure
- Virtual Machines
- Operating-System Generation
- System Boot
- Summary
- Exercises
75Exercises
76The End