CH 2
CH 2
Structures
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 2: Operating-System Structures
Operating System Concepts – 9th Edition 2 Silberschatz, Galvin and Gagne ©2013
Objectives
n T o describe the services an operating system provides to
users, processes, and other systems
n T o discuss the various w ays of structuring an operating
system
n T o explain how operating systems are installed and
customized and how they boot
Operating System Concepts – 9th Edition 3 Silberschatz, Galvin and Gagne ©2013
Operating System Services
n Operating systems provide an environment for execution of programs
and services to programs and users
n One set of operating-system services provides functions that are
helpful to the user:
l User interface - A lmost all operating systems have a user
interface (UI).
V aries betw een Command-Line (CLI), Graphics User Interface
(GUI), Batch
l Program execution - T he system must be able to load a program
into memory and to run that program, end execution, either
normally or abnormally (indicating error)
l I/O operations - A running program may req uire I/O, w hich may
involve a file or an I/O device
Operating System Concepts – 9th Edition 4 Silberschatz, Galvin and Gagne ©2013
Operating System Services (Cont.)
n One set of operating-system services provides functions that are helpful to
the user (Cont.):
l F ile-system manipulation - T he file system is of particular interest.
Programs need to read and w rite files and directories, create and delete
them, search them, list file Information, permission management.
l Communications – Processes may exchange information, on the same
computer or betw een computers over a netw ork
Communications may be via shared memory or through message
passing (packets moved by the OS)
l Error detection – OS needs to be constantly aw are of possible errors
M ay occur in the CPU and memory hardw are, in I/O devices, in user
program
For each type of error, OS should take the appropriate action to
ensure correct and consistent computing
D ebugging facilities can greatly enhance the user’s and programmer’s
abilities to efficiently use the system
Operating System Concepts – 9th Edition 5 Silberschatz, Galvin and Gagne ©2013
Operating System Services (Cont.)
n A nother set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing
l R esource allocation - W hen multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
M any types of resources - CPU cycles, main memory, file storage,
I/O devices.
l A ccounting - T o keep track of w hich users use how much and w hat
kinds of computer resources
l Protection and security - T he ow ners of information stored in a
multiuser or netw orked computer system may w ant to control use of
that information, concurrent processes should not interfere w ith each
other
Protection involves ensuring that all access to system resources is
controlled
Security of the system from outsiders req uires user authentication,
extends to defending external I/O devices from invalid access
attempts
Operating System Concepts – 9th Edition 6 Silberschatz, Galvin and Gagne ©2013
A View of Operating System Services
Operating System Concepts – 9th Edition 7 Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - CLI
Operating System Concepts – 9th Edition 8 Silberschatz, Galvin and Gagne ©2013
Bourne Shell Command Interpreter
Operating System Concepts – 9th Edition 9 Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - GUI
n User-friendly desktop metaphor interface
l Usually mouse, keyboard, and monitor
l Icons represent files, programs, actions, etc
l V arious mouse buttons over objects in the interface cause
various actions (provide information, options, execute function,
open directory (know n as a folder)
l Invented at X erox PA R C
n M any systems now include both CLI and GUI interfaces
l M icrosoft W indow s is GUI w ith CLI “command” shell
l A pple M ac OS X is “A q ua” GUI interface w ith UN IX kernel
underneath and shells available
l Unix and Linux have CLI w ith optional GUI interfaces (CD E,
K D E, GN OM E)
Operating System Concepts – 9th Edition 10 Silberschatz, Galvin and Gagne ©2013
Touchscreen Interfaces
Operating System Concepts – 9th Edition 11 Silberschatz, Galvin and Gagne ©2013
The Mac OS X GUI
Operating System Concepts – 9th Edition 12 Silberschatz, Galvin and Gagne ©2013
System Calls
n Programming interface to the services provided by the OS
n T ypically w ritten in a high-level language (C or C+ + )
n M ostly accessed by programs via a high-level A pplication
Programming Interface (A PI) rather than direct system
call use
n T hree most common A PIs are W in32 A PI for W indow s,
POSIX A PI for POSIX -based systems (including virtually all
versions of UN IX , Linux, and M ac OS X ), and J ava A PI for
the J ava virtual machine (J V M )
N ote that the system-call names used throughout this text are
generic
Operating System Concepts – 9th Edition 13 Silberschatz, Galvin and Gagne ©2013
Example of System Calls
n System call seq uence to copy the contents of one file to another file
Operating System Concepts – 9th Edition 14 Silberschatz, Galvin and Gagne ©2013
Example of Standard API
Operating System Concepts – 9th Edition 15 Silberschatz, Galvin and Gagne ©2013
System Call Implementation
Operating System Concepts – 9th Edition 16 Silberschatz, Galvin and Gagne ©2013
API – System Call – OS Relationship
Operating System Concepts – 9th Edition 17 Silberschatz, Galvin and Gagne ©2013
System Call Parameter Passing
Operating System Concepts – 9th Edition 18 Silberschatz, Galvin and Gagne ©2013
Parameter Passing via Table
Operating System Concepts – 9th Edition 19 Silberschatz, Galvin and Gagne ©2013
Types of System Calls
n Process control
l create process, terminate process
l end, abort
l load, execute
l get process attributes, set process attributes
l w ait for time
l w ait event, signal event
l allocate and free memory
l D ump memory if error
l D ebugger for determining bugs, single step execution
l Locks for managing access to shared data betw een processes
Operating System Concepts – 9th Edition 20 Silberschatz, Galvin and Gagne ©2013
Types of System Calls
n F ile management
l create file, delete file
l open, close file
l read, w rite, reposition
l get and set file attributes
n D evice management
l req uest device, release device
l read, w rite, reposition
l get device attributes, set device attributes
l logically attach or detach devices
Operating System Concepts – 9th Edition 21 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
n Information maintenance
l get time or date, set time or date
l get system data, set system data
l get and set process, file, or device attributes
n Communications
l create, delete communication connection
l send, receive messages if message passing model to host
name or process name
From client to server
l Shared-memory model create and gain access to memory
regions
l transfer status information
l attach and detach remote devices
Operating System Concepts – 9th Edition 22 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
n Protection
l Control access to resources
l Get and set permissions
l A llow and deny user access
Operating System Concepts – 9th Edition 23 Silberschatz, Galvin and Gagne ©2013
Examples of Windows and Unix System Calls
Operating System Concepts – 9th Edition 24 Silberschatz, Galvin and Gagne ©2013
Standard C Library Example
n C program invoking printf() library call, w hich calls w rite() system call
Operating System Concepts – 9th Edition 25 Silberschatz, Galvin and Gagne ©2013
Example: MS-DOS
n Single-tasking
n Shell invoked w hen system
booted
n Simple method to run
program
l N o process created
n Single memory space
n Loads program into memory,
overw riting all but the kernel
n Program exit -> shell
reloaded
Operating System Concepts – 9th Edition 26 Silberschatz, Galvin and Gagne ©2013
Example: FreeBSD
n Unix variant
n M ultitasking
n User login -> invoke user’s choice of shell
n Shell executes fork() system call to create
process
l Executes exec() to load program into
process
l Shell w aits for process to terminate
or continues w ith user commands
n Process exits w ith:
l code = 0 – no error
l code > 0 – error code
Operating System Concepts – 9th Edition 27 Silberschatz, Galvin and Gagne ©2013
System Programs
n System programs provide a convenient environment for program
development and execution. T hey can be divided into:
l F ile manipulation
l Status information sometimes stored in a F ile modification
l Programming language support
l Program loading and execution
l Communications
l Background services
l A pplication programs
n M ost users’view of the operation system is defined by system
programs, not the actual system calls
Operating System Concepts – 9th Edition 28 Silberschatz, Galvin and Gagne ©2013
System Programs
n Provide a convenient environment for program development and
execution
l Some of them are simply user interfaces to system calls;
others are considerably more complex
n Status information
l Some ask the system for info - date, time, amount of available
memory, disk space, number of users
l Others provide detailed performance, logging, and debugging
information
l T ypically, these programs format and print the output to the
terminal or other output devices
l Some systems implement a registry - used to store and
retrieve configuration information
Operating System Concepts – 9th Edition 29 Silberschatz, Galvin and Gagne ©2013
System Programs (Cont.)
n F ile modification
l T ext editors to create and modify files
l Special commands to search contents of files or perform
transformations of the text
n Programming-language support - Compilers, assemblers,
debuggers and interpreters sometimes provided
n Program loading and execution- A bsolute loaders, relocatable
loaders, linkage editors, and overlay-loaders, debugging systems
for higher-level and machine language
n Communications - Provide the mechanism for creating virtual
connections among processes, users, and computer systems
l A llow users to send messages to one another’s screens,
brow se w eb pages, send electronic-mail messages, log in
remotely, transfer files from one machine to another
Operating System Concepts – 9th Edition 30 Silberschatz, Galvin and Gagne ©2013
System Programs (Cont.)
n Background Services
l Launch at boot time
Some for system startup, then terminate
Some from system boot to shutdow n
l Provide facilities like disk checking, process scheduling, error
logging, printing
l R un in user context not kernel context
l K now n as services, subsystems, daemons
n A pplication programs
l D on’t pertain to system
l R un by users
l N ot typically considered part of OS
l Launched by command line, mouse click, finger poke
Operating System Concepts – 9th Edition 31 Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation
Operating System Concepts – 9th Edition 32 Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation (Cont.)
Operating System Concepts – 9th Edition 33 Silberschatz, Galvin and Gagne ©2013
Implementation
n M uch variation
l Early OSes in assembly language
l T hen system programming languages like A lgol, PL/1
l N ow C, C+ +
n A ctually usually a mix of languages
l Low est levels in assembly
l M ain body in C
l Systems programs in C, C+ + , scripting languages like PER L,
Python, shell scripts
n M ore high-level language easier to port to other hardw are
l But slow er
n Emulation can allow an OS to run on non-native hardw are
Operating System Concepts – 9th Edition 34 Silberschatz, Galvin and Gagne ©2013
Operating System Structure
n General-purpose OS is very large program
n V arious w ays to structure ones
l Simple structure – M S-D OS
l M ore complex -- UN IX
l Layered – an abstrcation
l M icrokernel -M ach
Operating System Concepts – 9th Edition 35 Silberschatz, Galvin and Gagne ©2013
Simple Structure -- MS-DOS
Operating System Concepts – 9th Edition 36 Silberschatz, Galvin and Gagne ©2013
Non Simple Structure -- UNIX
UN IX – limited by hardw are functionality, the original UN IX
operating system had limited structuring. T he UN IX OS
consists of tw o separable parts
l Systems programs
l T he kernel
Consists of everything below the system-call interface
and above the physical hardw are
Provides the file system, CPU scheduling, memory
management, and other operating-system functions;a
large number of functions for one level
Operating System Concepts – 9th Edition 37 Silberschatz, Galvin and Gagne ©2013
Traditional UNIX System Structure
Beyond simple but not fully layered
Operating System Concepts – 9th Edition 38 Silberschatz, Galvin and Gagne ©2013
Layered Approach
n T he operating system is divided
into a number of layers (levels),
each built on top of low er
layers. T he bottom layer (layer
0), is the hardw are;the highest
(layer N ) is the user interface.
n W ith modularity, layers are
selected such that each uses
functions (operations) and
services of only low er-level
layers
Operating System Concepts – 9th Edition 39 Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
n M oves as much from the kernel into user space
n M ach example of microkernel
l M ac OS X kernel (D arw in) partly based on M ach
n Communication takes place betw een user modules using
message passing
n Benefits:
l Easier to extend a microkernel
l Easier to port the operating system to new architectures
l M ore reliable (less code is running in kernel mode)
l M ore secure
n D etriments:
l Performance overhead of user space to kernel space
communication
Operating System Concepts – 9th Edition 40 Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
Operating System Concepts – 9th Edition 41 Silberschatz, Galvin and Gagne ©2013
Modules
n M any modern operating systems implement loadable kernel
modules
l Uses object-oriented approach
l Each core component is separate
l Each talks to the others over know n interfaces
l Each is loadable as needed w ithin the kernel
n Overall, similar to layers but w ith more flexible
l Linux, Solaris, etc
Operating System Concepts – 9th Edition 42 Silberschatz, Galvin and Gagne ©2013
Solaris Modular Approach
Operating System Concepts – 9th Edition 43 Silberschatz, Galvin and Gagne ©2013
Hybrid Systems
n M ost modern operating systems are actually not one pure model
l H ybrid combines multiple approaches to address
performance, security, usability needs
l Linux and Solaris kernels in kernel address space, so
monolithic, plus modular for dynamic loading of functionality
l W indow s mostly monolithic, plus microkernel for different
subsystem personalities
n A pple M ac OS X hybrid, layered, A q ua UI plus Cocoa programming
environment
l Below is kernel consisting of M ach microkernel and BSD Unix
parts, plus I/O kit and dynamically loadable modules (called
kernel extensions)
Operating System Concepts – 9th Edition 44 Silberschatz, Galvin and Gagne ©2013