1. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 1
Chapter 3: Operating-System StructuresChapter 3: Operating-System Structures
System Components
Operating System Services
System Calls
System Programs
System Structure
Virtual Machines
System Design and Implementation
2. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 2
Common System ComponentsCommon System Components
A system as large and complex as an OS can be
created only by partitioning it into smaller pieces
Process Management
Main Memory Management
File Management
I/O System Management
Secondary Management
Networking
Protection System
Command-Interpreter System
3. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 3
Process ManagementProcess Management
A process is a program in execution. A process needs
certain resources, including CPU time, memory, files,
and I/O devices, to accomplish its task.
A process is the unit of work in a system
The operating system is responsible for the following
activities in connection with process management.
Process creation and deletion.
Process suspension and resumption.
Provision of mechanisms for:
process synchronization
process communication
4. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 4
Main-Memory ManagementMain-Memory Management
Memory is a large array of words or bytes, each with its own address. It is
a repository of quickly accessible data shared by the CPU and I/O devices.
The CPU reads instructions from main memory (MM) during the
instruction-fetch cycle and both reads and writes data from MM during
the data-fetch cycle
Main memory is a volatile storage device. It loses its contents in the case of
system failure.
To improve both CPU utilization and response speed, several programs are
kept in memory
The following are some of the activities in connections with memory
management that are handled by the operating system :
Keep track of which parts of memory are currently being used and by
whom.
Decide which processes to load when memory space becomes available.
Allocate and deallocate memory space as needed.
5. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 5
File ManagementFile Management
A file is a collection of related information defined by its
creator. Commonly, files represent programs (both source
and object forms) and data.
The operating system is responsible for the following
activities in connections with file management:
File creation and deletion.
Directory creation and deletion.
Support of primitives for manipulating files and directories.
Mapping files onto secondary storage.
File backup on stable (nonvolatile) storage media.
6. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 6
I/O System ManagementI/O System Management
Hide the peculiarities of specific hardware devices from the
user
The I/O system consists of:
A memory management component that includes buffering,
caching and spooling
A general device-driver interface
Drivers for specific hardware devices
7. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 7
Secondary-Storage ManagementSecondary-Storage Management
Since main memory (primary storage) is volatile and too
small to accommodate all data and programs permanently,
the computer system must provide secondary storage to
back up main memory.
Most modern computer systems use disks as the principle
on-line storage medium, for both programs and data.
Because secondary storage is used frequently, it must be
used efficiently or else it will become a processing
bottleneck
The operating system is responsible for the following
activities in connection with disk management:
Free space management
Storage allocation
Disk scheduling
8. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 8
Networking (Distributed Systems)Networking (Distributed Systems)
A distributed system is a collection processors that do not
share memory or a clock. Each processor has its own local
memory.
The processors in the system are connected through a
communication network.
Communication takes place using a protocol.
A distributed system provides user access to various system
resources.
Access to a shared resource allows:
Computation speed-up
Increased data availability
Enhanced reliability
9. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 9
Protection SystemProtection System
Protection refers to a mechanism for controlling access
by programs, processes, or users to both system and user
resources.
The protection mechanism must:
distinguish between authorized and unauthorized usage.
specify the controls to be imposed.
provide a means of enforcement.
10. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 10
Command-Interpreter SystemCommand-Interpreter System
Serves as the interface between the user and the OS
User friendly, mouse based windows environment in the Macintosh
and in Microsoft Windows
In MS-DOS and UNIX, commands are typed on a keyboard and
displayed on a screen or printing terminal with the Enter or Return
key indicating that a command is complete and ready to be executed
Many commands are given to the operating system by control
statements which deal with:
process creation and management
I/O handling
secondary-storage management
main-memory management
file-system access
protection
networking
11. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 11
Command-Interpreter System (Cont.)Command-Interpreter System (Cont.)
The program that reads and interprets control statements is
called variously:
command-line interpreter
shell (in UNIX)
Its function is to get and execute the next command statement.
12. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 12
System CallsSystem Calls
System calls provide the interface between a running program and the
operating system.
For example – open input file, create output file, print message to
console, terminate with error or normally
Generally available as routines written in C and C++
Certain low-level tasks (direct hardware access) may be written in
assembly-language
Mostly accessed by programs via a high-level Application Program
Interface (API) rather than direct system call use
Provides portability (underlying hardware handled by OS)
Hides the detail from the programmer
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)
13. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 13
Example of System CallsExample of System Calls
System call sequence to copy the contents of one file to
another file
14. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 14
Example of Standard APIExample 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 file—the file to be read
LPVOID buffer—a buffer where the data will be read into and written from
DWORD bytesToRead—the number of bytes to be read into the buffer
LPDWORD bytesRead—the number of bytes read during the last read
LPOVERLAPPED ovl—indicates if overlapped I/O is being used
15. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 15
System Call ImplementationSystem 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)
16. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 16
API – System Call – OS RelationshipAPI – System Call – OS Relationship
17. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 17
Standard C Library ExampleStandard C Library Example
C program invoking printf() library call, which calls
write() system call
18. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 18
System Call Parameter PassingSystem 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
19. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 19
Passing Parameters as a TablePassing Parameters as a Table
20. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 20
Types of System CallsTypes of System Calls
Process control
end, abort, load, execute, allocate/free memory
File management
Create/delete file, open, close, read, write
Device management
Request/release device, read, write
Information maintenance
Get/set date or time, get process, get/set system data
Communications
Send/receive message, create/delete comm link
21. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 21
UNIX System CallsUNIX System Calls
22. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 22
MS-DOS ExecutionMS-DOS Execution
MS-DOS is an example of a single tasking system
Has command interpreter (shell) which is invoked at startup
time
Loads the program into memory, writing over most of the
shell to give the program as much memory as possible
The instruction pointer is set to the first instruction of the
program and it begins running
Programs either terminates normally or abends providing a
return code that is saved in system memory
The resident portion of the shell resumes execution, reloads
remainder of the shell and makes the previous error code
available to the user or next program
23. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 23
MS-DOS ExecutionMS-DOS Execution
At System Start-up Running a Program
24. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 24
UNIX Running Multiple ProgramsUNIX Running Multiple Programs
FreeBSD is a multitasking system
Shell accepts a command to run a program but, unlike MS-
DOS, continues to run while the other program is executing
To start a new process, the shell executes a fork system call
which enables another program to be loaded into memory and
executed
A process can run in the “background” but then it can not accept
input from the keyboard (as it is dedicated to the shell) but can
read and writes files
The shell again waits for further commands – run another
program, monitor the progress of the running processes,
change priorities, etc.
When a process terminates it issues an exit system call
returning a status code
26. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 26
System ProgramsSystem Programs
System programs provide a convenient environment for program
development and execution. The can be divided into:
File manipulation
Status information (date,time, # of users, free memory etc.)
File modification (text editors)
Programming language support (compilers, assemblers, etc)
Program loading and execution (loaders, linkage editors)
Communications (create virtual connections among processes, users
and different computer systems)
System utilities or application programs (web browsers, word
processing, spreadsheets etc)
Most users’ view of the operating system is defined by system
programs, not the actual system calls.
27. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 27
OS Design ImplementationOS Design Implementation
Mechanisms determine how to do something, policies
decide what will be done.
The separation of policy from mechanism is a very
important principle in designing OSs
It allows maximum flexibility if policy decisions are to be
changed later.
The mechanism that implements the policy to give priority to I/O
intensive processes over CPU intensive processes should be
written in a general way so that if the policy is changed no or
minimal change to the mechanism would be required
The timer provides is a mechanism providing CPU protection.
How long it runs for a particular user is a policy decision.
28. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 28
System ImplementationSystem Implementation
Traditionally written in assembly language, operating systems can now
be written in higher-level languages.
Code written in a high-level language:
can be written faster.
is more compact.
is easier to understand and debug.
Opponents to OSs written high-level language claim slower
performance and increased storage
Proponents argue:
Modern compilers can produce highly optimized code
Todays OSs run on highly complex hardware which can overwhelm
the programmer with details
Better data structures and algorithms will truly improve the
performance of OSs
Only a small amount of code is critical to high performance –
bottlenecks can be replaced with assembler code later on
An operating system is far easier to port (move to some other
hardware) if it is written in a high-level language.
29. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 29
Operating System StructureOperating System Structure
MS-DOS – written to provide the
most functionality in the least space
Not well divided into modules
Designed without realizing it
was going to become so popular
Although MS-DOS has some
structure, its interfaces and
levels of functionality are not
well separated
Vulnerable to system crashes
when a user program fails
Written for Intel 8088 which
had no dual mode or hardware
protection
MS-DOS layer structureMS-DOS layer structure
30. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 30
Operating System StructureOperating System Structure
UNIX – the original UNIX operating system had limited
structuring due to limited hardware functionality.
The UNIX OS consists of two separable parts.
Systems programs
The kernel – series of interfaces and device drivers
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.
All this functionality in one level makes UNIX difficult to
enhance – difficult to determine impact of change in one part of
the kernel on other parts
31. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 31
UNIX System StructureUNIX System Structure
kernel
32. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 32
Layered ApproachLayered 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.
Simplifies debugging and system
verification – each layer only uses
those below it, so by testing from
bottom up, you isolate errors to the
layer being tested
Requires careful definition of layers
Less efficient as each layer adds
overhead to the system increasing
overall time for a system call to
execute
An operating system layerAn operating system layer
33. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 33
Layered ApproachLayered Approach
These limitations have led to the design of OSs with fewer layers each
with more functionality
Provides most of the advantages of modularized code while avoiding
the difficulties of layer definition and interaction
OS/2, a descendent of MS-DOS, adds multitasking and dual-mode
operation
Designed in a more layered approach than MS-DOS
Direct access to low-level facilities is not allowed; this gives the OS more
control over the hardware and more knowledge of which resources each
user program is using
The first release of Windows NT had a highly layered approach but it delivered
low performance compared to Windows 95
NT 4.0 addressed that problem in part by moving layers from user space to
kernel space and more closely integrating them
35. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 35
Microkernel System StructureMicrokernel System Structure
In the mid 1980s, researchers at Carnegie Mellon developed the Mach
microkernel OS
Moves nonessential components from the kernel into “user” space resulting
in a smaller kernel
Main function of the microkernel is to provide a communication facility
between the client program and various services that are also running in
user space
Communication takes place between user modules using message passing.
Benefits:
easier to extend a microkernel
all new services are added to user space
easier to port the operating system to new architectures
more reliable and secure
less code is running in kernel mode
Apple MacOS X Server OS is based on the Mach kernel
maps system calls into messages to the appropriate user-level services
36. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 36
ModulesModules
Best, current technology for OS design involves using
object oriented programming techniques to create a
modular kernel
Kernel dynamically links in additional services either
during boot time or run time
Uses dynamically loadable modules (Solaris, Linux, Mac OS X)
Kernel provides core services and others implemented dynamically
Similar but more efficient than microkernel design because
modules do not need to invoke message passing in order to
communicate
37. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 37
Solaris loadable modulesSolaris loadable modules
38. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 38
Virtual MachinesVirtual Machines
A virtual machine takes the layered approach to its logical
conclusion. It treats hardware and the operating system kernel as
though they were all hardware.
A virtual machine not provide any additional functionality but
provides an interface identical to the underlying bare hardware.
Each process is provided with a (virtual) copy of the underlying
computer
The operating system creates the illusion that a process has its own
processor with its own (virtual) memory.
The resources of the physical computer are shared to create the
virtual machines.
CPU scheduling can create the appearance that users have their
own processor.
Spooling and a file system can provide virtual card readers and
virtual line printers.
A normal user time-sharing terminal serves as the virtual
machine operator’s console.
39. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 39
System ModelsSystem Models
Non-virtual Machine Virtual Machine
40. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 40
Virtual MachinesVirtual Machines
The virtual-machine concept provides complete protection of
system resources since each virtual machine is isolated from
all other virtual machines. This isolation, however, permits
no direct sharing of resources.
A virtual-machine system is 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.
The virtual machine concept is difficult to implement due to
the effort required to provide an exact duplicate to the
underlying machine
Virtual machines are a means to solve system compatibility
problems
Windows applications to run on Linux-based computers
Intel instructions are translated into the native instruction set
41. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 41
Java Virtual MachineJava Virtual Machine
A platform is the hardware or software
environment in which a program runs. Some of
the most popular platforms are Windows 2000,
Linux, Solaris, and MacOS.
Most platforms can be described as a
combination of the operating system and
hardware. The Java platform differs from most
other platforms in that it's a software-only
platform that runs on top of other hardware-
based platforms.
Compiled Java programs are platform-neutral
bytecodes executed by a Java Virtual Machine
(JVM).
The JVM is specific for each system and it
abstracts the system in a standard way to the
Java program eliminating code changes when
ported from one platform to another
42. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 42
Communication ModelsCommunication Models
Communication between processes may take place using either
message passing or shared memory.
Message passing
Information is exchanged through an interprocess communication
facility provided by the OS
Computers have host names, processes have process names for
identification purposes
Useful when smaller number of data need to be exchanged
Easier to implement than shared memory
Shared memory
Processes use map memory system calls to gain access to regions of
memory owned by other processes
Allows maximum speed and convenience of communication
Problems arise in the area of protection and synchronization
43. Operating System Concepts / Silberschatz / Ch 3 Oper Sys StrcuturesSlide 43
Communication ModelsCommunication Models
Message Passing Shared Memory