Chapter 2: Operating-System Structures
A View of Operating System Services
System Calls
Programming interface to the services provided by the OS
Typically written in a high-level language (C or C++) Mostly accessed by programs via a high-level
Application Programming Interface (API)
Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)
Example of System Calls
System call sequence to copy the contents of one file to another file
Example of Standard API
System 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)
API – System Call – OS Relationship
System Call Parameter Passing
Often, more information is required than simply identity of desired system call
Exact type and amount of information vary according to OS and call
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
Parameter Passing via Table
Examples of Windows and Unix System Calls
Standard C Library Example
C program invoking printf() library call, which calls write() system call
Operating System Design and Implementation
Important principle to separate Policy: What will be done?
Mechanism: How to do it?
Mechanisms determine how to do something, policies
decide what will be done
The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later
Operating System Structure
General-purpose OS is very large program Various ways to structure one as follows
(1) Monolithic Structure: all the functionality of the kernel is placed in a single, static binary file that runs in a single address space.
– advantages: speed and efficiency due to less overhead in the system-call interface and fast communication within kernel
– disadvantages: difficult to implement and extend. (2) Layered Approach
(3) Microkernels
(4) Modules
(5) Hybrid Systems
UNIX
UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts
Systems programs The kernel
Consists of everything below the system-call interface and above the physical hardware
Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level
Traditional UNIX System Structure
Beyond simple but not fully layered
Linux System Structure
Similar to Unix, but has modular design that allows kernel to be modified during run- time
Layered Approach
The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.
With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers
Advantages: – easy to design, implement, debug/verify
Disadvantages: Each additional layer results in additional overhead
Microkernel System Structure
Moves as much from the kernel into user space
Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
Communication takes place between user modules using
message passing
Benefits:
Easier to extend a microkernel
Easier to port the operating system to new architectures More reliable (less code is running in kernel mode)
More secure
Detriments:
Performance overhead of user space to kernel space communication
Microkernel System Structure
Application Program
user mode
File System
Device Driver
messages
Interprocess Communication
memory CPU managment scheduling
microkernel
messages
kernel mode
hardware
Modules
Most modern operating systems implement loadable 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 Linux, Solaris, etc
Hybrid Systems
Most modern operating systems actually not one pure model Hybrid combines multiple approaches to address
performance, security, usability needs
Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic loading of functionality
Windows mostly monolithic, plus microkernel for different subsystem personalities
Apple Mac OS X hybrid kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions)
End of Chapter 2