Professional Documents
Culture Documents
Chapter 1
Introduction
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
What Is An Operating System?
Lots of hardware !!
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
What is an Operating System (2)?
A. Frank - P. Weisberg
Services provided by an OS
• Facilities for program creation
– editors, compilers, linkers, debuggers, etc.
• Program execution
– loading in memory, I/O and file initialization.
• Access to I/O and files
– deals with the specifics of I/O and file formats.
• System access
– resolves conflicts for resource contention.
– protection in access to resources and data.
A. Frank - P. Weisberg
Where is the software?
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System as an Extended
Machine
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System as a Resource
Manager
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
History of Operating Systems
Generations:
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Transistors and Batch Systems (1)
A multiprogramming system
with three jobs in memory.
More third generation
• Time Sharing (CTSS)
• Multics
• Unix
• Linux
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Fourth generation
• PCs
• Network Operating Systems
• Distributed Operating Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Operating system timeline
• First generation: 1945 – 1955
– Vacuum tubes
– Plug boards
• Second generation: 1955 – 1965
– Transistors
– Batch systems
• Third generation: 1965 – 1980
– Integrated circuits
– Multiprogramming
• Fourth generation: 1980 – present
– Large scale integration
– Personal computers
• Next generation: ???
– Systems connected by high-speed networks?
– Wide area resource management?
First generation: direct input
• Run one job at a time
– Enter it into the computer (might require rewiring!)
– Run it
– Record the results
• Problem: lots of wasted computer time!
– Computer was idle during first and last steps
– Computers were very expensive!
• Goal: make better use of an expensive commodity: computer
time
Chapter 1
Structure of a typical 2nd generation job
Data for
$END
program
$RUN
FORTRAN $LOAD
program
$FORTRAN
$JOB, 10,6610802, ETHAN MILLER
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Device Driver
• OS software that talks to controller-gives
commands, accepts responses
• Each controller manufacturer supplies a driver
for each OS
• Driver runs in kernel mode
• Controller has registers which are used to
communicate with the driver
• Three modes of communication
• Polling
• Interrupts
• DMA
Tanenb aum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O by polling device
• Driver issues command to controller
• Driver polls device until it is ready
• E.g. Send character to printer controller and
poll until it is ready to accept the next
character
• Big use of CPU
• Called programmed I/O-not really used any
more
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O by DMA
• Special (controller) chip
• Avoids using the CPU as part of the transfer
to/from memory
• CPU tells chip to set up transfer and take care
of it
• Chip does as it is told and interrupts CPU when
it is finished
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The bus hierarchy
• In the beginning there was one bus-couldn’t
handle the traffic when cpu and memories got
faster and bigger
• Create a hierarchy of faster buses (PCI) and
specialized buses (SCSI, USB)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Pentium System Buses
Execute
Fetch Decode unit
unit unit
Fetch Decode
unit unit Execute
unit
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
A Process Tree
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process
• Can communicate with one another
• Have UID’s and group ID’s (GID)
• Can communicate with one another (IPC)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process Management
• A process is a program in execution. It is a unit of work
within the system. Program is a passive entity, process is
an active entity.
• Process needs resources to accomplish its task
– CPU, memory, I/O, files
– Initialization data
• Process termination requires reclaim of any reusable
resources
• Single-threaded process has one program counter
specifying location of next instruction to execute
– Process executes instructions sequentially, one at a time, until completion
• Multi-threaded process has one program counter per
thread
• Typically system has many processes, some user, some
operating system running concurrently on one or more
CPUs
– Concurrency by multiplexing the CPUs among the processes / threads
Process Management Activities
The operating system is responsible for the following
activities in connection with process management:
• Creating and deleting both user and system
processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• Providing mechanisms for deadlock handling
Main Memory
• RAM
• ROM-can’t be changed. Fast, cheap
• e.g. keeps bootstrap OS loader
• EEPROM (Electrically Erasable PROM) Can be
re-written, but slowly
• e.g. serves as films in digital cameras, as
disk in portable music players
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Memory Management
• To execute a program all (or part) of the instructions must
be in memory
• All (or part) of the data that is needed by the program
must be in memory.
• Memory management determines what is in memory and
when
– Optimizing CPU utilization and computer response to users
• Memory management activities
– Keeping track of which parts of memory are currently being used and by
whom
– Deciding which processes (or parts thereof) and data to move into and
out of memory
– Allocating and deallocating memory space as needed
Storage Management
• OS provides uniform, logical view of information storage
– Abstracts physical properties to logical storage unit - file
– Each medium is controlled by device (i.e., disk drive, tape drive)
• Varying properties include access speed, capacity, data-
transfer rate, access method (sequential or random)
• File-System management
– Files usually organized into directories
– Access control on most systems to determine who can access what
– OS activities include
• Creating and deleting files and directories
• Primitives to manipulate files and directories
• Mapping files onto secondary storage
• Backup files onto stable (non-volatile) storage media
Mass-Storage Management
• Usually disks used to store data that does not fit in main
memory or data that must be kept for a “long” period of
time
• Proper management is of central importance
• Entire speed of computer operation hinges on disk
subsystem and its algorithms
• OS activities
– Free-space management
– Storage allocation
– Disk scheduling
• Some storage need not be fast
– Tertiary storage includes optical storage, magnetic tape
– Still must be managed – by OS or applications
– Varies between WORM (write-once, read-many-times) and RW (read-
write)
Storage pyramid
Capacity Access latency
< 1 KB Registers 1 ns Better
Instructionn
3 2
1: Interrupt Instructionn+1
5 Interrupt Disk
CPU controller controller
1 6 4 Operating
system 3: Return
Interrupt handler
2: Process interrupt
• Left: sequence as seen by hardware
– Request sent to controller, then to disk
– Disk responds, signals disk controller which tells interrupt
controller
– Interrupt controller notifies CPU
• Right: interrupt handling (software point of view)
Computer Hardware Review
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Caches
Main memory is divided into cache lines (64 bytes)
0-63 in line 1, 64-127 in line 2
When program reads a word-cache hardware checks to
see if in cache.
If so, then have a cache hit (2 cycles).
Otherwise, make request of main memory over the
bus (expensive)
Cache is expensive and is therefore limited in size
Can have cache hierarchies
Cache other things, like URL addresses
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The 4 Cache Questions
• When to put a new item into the cache? (on a
cache miss)
• Which cache line to put the new item in?
(memory word determines which line)
• Which item to remove from the cache when a
slot is needed? (same line new data goes into)
• Where to put a newly evicted item in main
memory? (memory address determines this)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Multithreaded and Multicore Chips
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Operating System Zoo
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Operating System Concepts
• Processes
• Address spaces
• Files
• Input/Output
• Protection
• The shell
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Views of an Operating System
• There are three classical views (in literature):
1. Resource Manager – manages and allocates resources.
2. Control program – controls the execution of user programs and
operations of I/O devices.
3. Command Executer – Provides an environment for running user
commands.
• But one more modern view: the Operating System as a
Virtual Machine.
A. Frank - P. Weisberg
1. Resource Manager
• Resource Manager:
– Manages and protects multiple computer resources: CPU,
Processes, Internal/External memory, Tasks,
Applications, Users, Communication channels, etc…
– Handles and allocates resources to multiple users or
multiple programs running at the same time and space
(e.g., processor time, memory, I/O devices).
– Decides between conflicting requests for efficient and
fair resource use (e.g., maximize throughput, minimize
response time).
• Sort of a bottom-up view.
A. Frank - P. Weisberg
OS as a Resource Manager
A. Frank - P. Weisberg
Resource Manager oriented OS names
• DEC RSX – Resource Sharing eXecutive
• MIT Multics – MULTiplexed Information and
Computing Services
• IBM MFT/MVT – Multiple Fixed/Variable
Tasks
• IBM MVS – Multiple Virtual Storage
• DEC VMS – Virtual Memory System
• MVS TSO – Time Sharing Option
• CTSS – Compatible Time Sharing System
• IBM VM – Virtual machine
A. Frank - P. Weisberg
2. Control Program
• Control Program:
– Manages all the components of a complex
computer system in an integrated manner.
– Controls the execution of user programs
and I/O devices to prevent errors and
improper use of computer resources.
– Looks over and protects the computer:
Monitor, Supervisor, Executive,
Controller, Master, Coordinator ….
• Sort of a black box view.
A. Frank - P. Weisberg
Control program oriented OS names
• Unisys MCP – Master Control Program
• DR CP/M – Control Program/Microcomputer
• IBM VM/CP – VM Control Program
• IBM AIX – Advanced Interactive eXecutive
• DEC RSX – Resource Sharing eXecutive
A. Frank - P. Weisberg
3. Command Executer
• Command Executer:
– Interfaces between the users and machine.
– Supplies services/utilities to users.
– Provides the users with a convenient CLI
(Command Language Interface), also
called a Shell (in UNIX), for entering the
user commands.
• Sort of a top-down view.
A. Frank - P. Weisberg
Command Executer oriented OS names
• IBM AIX – Advanced Interactive Executive
• IBM VM/CMS – Conversational monitor System
A. Frank - P. Weisberg
File directory
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Special files
• Special files-can use same calls for I/O as for
files. OS treats them as files.
• Block special files (disks)
• Character special files (line printers,
modems)
• Kept in /dev directory, e.g. /dev/lp is line
printer
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Unix Pipe
Processes communicate by writing into/reading from a file
in Unix
A and B write into the pipe and read from the pipe.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O, Protection/Shell
• I/O-big part of OS
• Protection-UNIX uses rwx bits for each file
• 3 bits for owner, 3 for group, 3 for everyone else
• Shell (command interpreter)
• UNIX
• Has lots of flavors-sh,bash,csh,ssh…..
• Sort<file1>file2
• Cat file 1 file 2 file3 | sort > /dev/lp
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls
• Interface between user programs and OS
• Varies from OS to OS
• System call issued by user program
• Call uses a library call of the same name
• Library routine puts machine into kernel modes
(by issuing a special instruction)
• Finds actual routine for system call in a table
• Does the work involved in the call
• Returns to user program
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Unix Read System Call
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for Process Management
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Memory Layout
Processes have three segments:
text, data, and stack.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Shell
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Fork
• Pid=fork( )
• Duplicates parent process completely
Everything duplicated -data,registers,fd’s
• Fork returns a value (pid)
• Zero in child
• Child’s PID in parent
• Used to differentiate child from parent
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Execve
• Replaces process’ core image by the file named
in its invocation
• Execve(name,arg,environp) has 3 parameters
• Name of file (e.g. cp command)
• Arg-pointer to argument array
• Environp-pointer to environment array
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Excve (example)
• cp f1 f2 is located by execve and parameters
are passed to it by execve
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for File Management
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File mode
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for Directory and File
Management
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Linking
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Other System Calls
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Windows Win32 API
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Monolithic Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Layered Systems-THE operating system
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Microkernels
• Small number of processes are allowed in the
kernel
• Minimizes effects of bugs
• Don’t want bug in driver to crash system
• Put mechanism in kernel and policy outside the
kernel
• Mechanism- schedule processes by priority
scheduling algorithm
• Policy-assign process priorities in user space
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Microkernels
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Client-Server Model
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual Machines (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual Machines (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The World According to C
• The C language
• Header files
• Large programming projects
• The model of run time
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Model of Run Time