You are on page 1of 100

Advanced Operating Systems:

Review of Operating System


Concepts
Learning Objectives
Operating System Definition(s)
Review of Computer System Architecture
Functions of an Operating Systems
Design Approaches
Processes, Threads, Synchronization, and Deadlock
Motivation for Advanced Operating Systems
Types of Advanced Operating Systems

Review of Operating System Concepts 2


What is an Operating System?

An operating system is a program or a set of programs


that manage computer resources

A program that acts as an intermediary between a user


of a computer and the computer hardware

Operating system goals:


Execute user programs and make solving user problems
easier
Make the computer system convenient to use
Use the computer hardware in an efficient manner

Review of Operating System Concepts 3


Operating System Definition

OS is a resource allocator
Manages all resources.
Decides between conflicting requests for efficient and
fair resource use.

OS is a control program
Controls execution of programs to prevent errors and
improper use of the computer.

Review of Operating System Concepts 4


Operating System Definition

No universally accepted definition.

Everything a vendor ships when you order an


operating system is good approximation
But varies wildly.

The one program running at all times on the


computer is the kernel.
Everything else is either a system program (ships with the
operating system) or an application program

Review of Operating System Concepts 5


Operating System Definition

Review of Operating System Concepts 6


What Operating Systems Do

Turn ugly interface into beautiful


abstractions

Advanced Operating Systems 7


Computer System Organization
Computer-system operation
One or more CPUs, device controllers connect through common bus providing access to
shared memory
Concurrent execution of CPUs and devices competing for memory cycles

Review of Operating System Concepts 8


Computer-System Operation

I/O devices and the CPU can execute concurrently


Each device controller is in charge of a particular device
type
Each device controller has a local buffer
CPU moves data from/to main memory to/from local
buffers
I/O is from the device to local buffer of controller
Device controller informs CPU that it has finished its
operation by causing an interrupt

Review of Operating System Concepts 9


How a Modern Computer Works

Review of Operating System Concepts 10


Computer-System Architecture
Most systems use a single general-purpose processor (PDAs
through mainframes)
Most systems have special-purpose processors as well

Multiprocessors systems growing in use and importance


Also known as parallel systems, tightly-coupled systems
Advantages include
Increased throughput
Economy of scale
Increased reliability graceful degradation or fault tolerance
Two types
Asymmetric Multiprocessing
Symmetric Multiprocessing

Review of Operating System Concepts 11


Symmetric Multiprocessing
Architecture

Review of Operating System Concepts 12


A Dual-Core Design

Review of Operating System Concepts 13


Clustered Systems

Like multiprocessor systems, but multiple systems


working together
Usually sharing storage via a storage-area network (SAN)
Provides a high-availability service which survives failures
Asymmetric clustering has one machine in hot-standby mode
Symmetric clustering has multiple nodes running applications,
monitoring each other
Some clusters are for high-performance computing (HPC)
Applications must be written to use parallelization

Review of Operating System Concepts 14


Operating System Structure
Multiprogramming needed for efficiency
Single user cannot keep CPU and I/O devices busy at all times.
Multiprogramming organizes jobs (code and data) so CPU always has one to execute.
A subset of total jobs in system is kept in memory.
One job selected and run via job scheduling.
When it has to wait (for I/O for example), OS switches to another job.

Timesharing (multitasking) is logical extension in which CPU switches jobs so


frequently that users can interact with each job while it is running, creating
interactive computing
Response time should be < 1 second
Each user has at least one program executing in memory process
If several jobs ready to run at the same time CPU scheduling
If processes dont fit in memory, swapping moves them in and out to run
Virtual memory allows execution of processes not completely in memory

Review of Operating System Concepts 15


Functions of an Operating System

Resource Management
Process Management
Time Management (CPU and disk scheduling)
Space Management (memory and disk space)
Accounting and status information

User Friendliness (The Beautification Principle)


Execution Environment.
Error Detection and Handling.
Protection and Security.
Fault Tolerance and Failure Recovery.

Review of Operating System Concepts 16


Process Management
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

Review of Operating System Concepts 18


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

Review of Operating System Concepts 19


Diagram of Process State

Review of Operating System Concepts 20


Process Control Block (PCB)

Information associated with each process


Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information

Review of Operating System Concepts 21


Process Control Block (PCB)

Review of Operating System Concepts 22


CPU Switch From Process to Process

Review of Operating System Concepts 23


Process Scheduling Queues
Job queue set of all processes in the system

Ready queue set of all processes residing in


main memory, ready and waiting to execute

Device queues set of processes waiting for an


I/O device

Processes migrate among the various queues

Review of Operating System Concepts 24


Ready Queue And Various
I/O Device Queues

Review of Operating System Concepts 25


Process Creation
Parent process create children processes, which,
in turn create other processes, forming a tree of
processes
Generally, process identified and managed via a
process identifier (pid)
Resource sharing
Parent and children share all resources
Children share subset of parents resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate

Review of Operating System Concepts 26


Process Creation (Cont.)

Address space
Child duplicate of parent
Child has a program loaded into it

UNIX examples
fork system call creates new process
exec system call used after a fork to replace the
process memory space with a new program

Review of Operating System Concepts 27


Process Creation

Review of Operating System Concepts 28


C Program Forking Separate Process
int main()
{
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}

Review of Operating System Concepts 29


Interprocess Communication
Processes within a system may be independent or cooperating.
Independent process cannot affect or be affected by the
execution of another process
Cooperating process can affect or be affected by other
processes, including sharing data.
Reasons for cooperating processes:
Information sharing
Computation speedup
Modularity
Convenience
Cooperating processes need interprocess communication (IPC)
Two models of IPC
Shared memory
Message passing
Review of Operating System Concepts 30
Communications Models

Review of Operating System Concepts 31


Time Management
Objectives

To introduce CPU scheduling, which is the basis


for multiprogrammed operating systems.

To describe various CPU-scheduling algorithms.

To discuss evaluation criteria for selecting a


CPU-scheduling algorithm for a particular
system.

Review of Operating System Concepts 33


Basic Concepts

Maximum CPU utilization obtained with


multiprogramming.

CPUI/O Burst Cycle Process execution consists of


a cycle of CPU execution and I/O wait

CPU burst distribution

Review of Operating System Concepts 34


Alternating Sequence of CPU and
I/O Bursts

Review of Operating System Concepts 35


CPU Scheduler
Selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them

CPU scheduling decisions may take place when a process:


Switches from running to waiting state
Switches from running to ready state
Switches from waiting to ready
Terminates

Scheduling under 1 and 4 is nonpreemptive

All other scheduling is preemptive

Review of Operating System Concepts 36


Dispatcher
Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler; this
involves:
switching context
switching to user mode.
jumping to the proper location in the user program to
restart that program

Dispatch latency time it takes for the dispatcher to


stop one process and start another running

Review of Operating System Concepts 37


Scheduling Criteria

CPU utilization keep the CPU as busy as possible

Throughput # of processes that complete their execution per time unit

Turnaround time amount of time to execute a particular process

Waiting time amount of time a process has been waiting in the ready
queue

Response time amount of time it takes from when a request was


submitted until the first response is produced, not output (for time-
sharing environment)

Review of Operating System Concepts 38


Scheduling Algorithm Optimization
Criteria
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time

Review of Operating System Concepts 39


First-Come, First-Served (FCFS)
Scheduling
Process Burst Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:

P1 P2 P3

0 24 27 30

Waiting time for P1 = 0; P2 = 24; P3 = 27


Average waiting time: (0 + 24 + 27)/3 = 17

Review of Operating System Concepts 40


FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order:
P2 , P3 , P1
The Gantt chart for the schedule is:

P2 P3 P1

0 3 6 30
Waiting time for P1 = 6; P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Convoy effect short process behind long process
Review of Operating System Concepts 41
Disk Scheduling
The operating system is responsible for using hardware
efficiently for the disk drives, this means having a fast
access time and disk bandwidth.
Access time has two major components
Seek time is the time for the disk are to move the heads to the
cylinder containing the desired sector.
Rotational latency is the additional time waiting for the disk to
rotate the desired sector to the disk head.
Minimize seek time
Seek time seek distance
Disk bandwidth is the total number of bytes transferred,
divided by the total time between the first request for
service and the completion of the last transfer
Review of Operating System Concepts 42
Disk Scheduling (Cont.)

Several algorithms exist to schedule the servicing


of disk I/O requests.

We illustrate them with a request queue (0-199)

98, 183, 37, 122, 14, 124, 65, 67

Head pointer 53

Review of Operating System Concepts 43


FCFS
Illustration shows total head movement of 640 cylinders

Review of Operating System Concepts 44


Shortest-Seek-Time-First SSTF
Selects the request with the minimum seek time
from the current head position.

SSTF scheduling is a form of SJF(shortest-job-


first) scheduling; may cause starvation of some
requests.

Illustration shows total head movement of 236


cylinders

Review of Operating System Concepts 45


SSTF (Cont.)

Review of Operating System Concepts 46


Space Management
Memory Management
All data in memory before and after processing
All instructions in memory in order to execute
Memory management determines what is in memory
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
Review of Operating System Concepts 48
Paging
Logical address space of a process can be noncontiguous;
process is allocated physical memory whenever the latter is
available.
Divide physical memory into fixed-sized blocks called frames
(size is power of 2, between 512 bytes and 8,192 bytes)
Divide logical memory into blocks of same size called pages
Keep track of all free frames
To run a program of size n pages, need to find n free frames and
load program
Set up a page table to translate logical to physical addresses
Internal fragmentation

Review of Operating System Concepts 49


Address Translation Scheme
Address generated by CPU is divided into:
Page number (p) used as an index into a page table
which contains base address of each page in physical
memory
Page offset (d) combined with base address to define
the physical memory address that is sent to the memory
unit
page number page offset
m-n n
p d

For given logical address space 2m and page size 2n

Review of Operating System Concepts 50


Paging Hardware

Review of Operating System Concepts 51


Paging Model of Logical and
Physical Memory

Review of Operating System Concepts 52


Paging Hardware With TLB

Review of Operating System Concepts 53


Effective Access Time
Associative Lookup = time unit

Assume memory cycle time is 1 microsecond

Hit ratio percentage of times that a page number is found in


the associative registers; ratio related to number of associative
registers

Hit ratio =

Effective Access Time (EAT)


EAT = (1 + ) + (2 + )(1 )
=2+

Review of Operating System Concepts 54


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 dirs
Mapping files onto secondary storage
Backup files onto stable (non-volatile) storage media

Review of Operating System Concepts 55


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
Varies between WORM (write-once, read-many-times) and RW (read-
write)

Review of Operating System Concepts 56


A Typical File Control Block

Review of Operating System Concepts 57


Contiguous Allocation of Disk Space

Review of Operating System Concepts 58


Linked Allocation

Review of Operating System Concepts 59


Example of Indexed Allocation

Review of Operating System Concepts 60


Combined Scheme: UNIX UFS
(4K bytes per block)

Review of Operating System Concepts 61


Schematic View of NFS Architecture

Review of Operating System Concepts 62


RAID Structure

RAID multiple disk drives provides reliability


via redundancy

Increases the mean time to failure

Frequently combined with NVRAM to improve


write performance

RAID is arranged into six different levels


Review of Operating System Concepts 63
RAID (Cont.)
Several improvements in disk-use techniques involve the use of
multiple disks working cooperatively
Disk striping uses a group of disks as one storage unit
RAID schemes improve performance and improve the
reliability of the storage system by storing redundant data
Mirroring or shadowing (RAID 1) keeps duplicate of each disk
Striped mirrors (RAID 1+0) or mirrored stripes (RAID 0+1)
provides high performance and high reliability
Block interleaved parity (RAID 4, 5, 6) uses much less
redundancy
RAID within a storage array can still fail if the array fails, so
automatic replication of the data between arrays is common
Frequently, a small number of hot-spare disks are left
unallocated, automatically replacing a failed disk and having
data rebuilt onto them

Review of Operating System Concepts 64


RAID Levels

Review of Operating System Concepts 65


RAID Levels

Review of Operating System Concepts 66


RAID Levels

Review of Operating System Concepts 67


RAID (0 + 1) and (1 + 0)

Review of Operating System Concepts 68


Protection and Security
Protection any mechanism for controlling access of processes or users to
resources defined by the OS

Security defense of the system against internal and external attacks


Huge range, including denial-of-service, worms, viruses, identity theft, theft of
service

Systems generally first distinguish among users, to determine who can do


what
User identities (user IDs, security IDs) include name and associated number,
one per user
User ID then associated with all files, processes of that user to determine
access control
Group identifier (group ID) allows set of users to be defined and controls
managed, then also associated with each process, file
Privilege escalation allows user to change to effective ID with more rights

Review of Operating System Concepts 69


Design Approaches

Separation of mechanism and policy


Policy: what should be done?
Mechanism: how to do it?

Good operating systems must separate


policies from mechanisms.
Policies make use of underlying mechanisms
Results in a more flexible and adaptive system

Review of Operating System Concepts 70


Transition from User to Kernel Mode

Timer to prevent infinite loop / process hogging resources


Set interrupt after specific period
Operating system decrements counter
When counter zero generate an interrupt
Set up before scheduling process to regain control or terminate
program that exceeds allotted time

Review of Operating System Concepts 71


Design Approach (cont.)
Layered Approach
Modular design
Each layer provides entry points for higher layers
Each layer can only use functions from lower
layer(s)

The challenging part is splitting the OS


functionality appropriately such that there are no
circular dependencies

Review of Operating System Concepts 72


Review of Operating System Concepts 73
Review of Operating System Concepts 74
Review of Operating System Concepts 75
Design Approaches (cont.)
Kernel-Based Approach
A small set of truly primitive operations
Mechanism only
Policy decisions are made outside the kernel

Demand for more complex mechanism has bloated


kernels
Too much in kernel low flexibility
Too little in kernel low functionality

Example is Hydra

Review of Operating System Concepts 76


Review of Operating System Concepts 77
Design Approaches (cont.)

Virtual Machine Approach


Give each user the illusion he has the machine to
himself
The virtual machine can have different capabilities
than the real machine
Each user can run a different OS

Example: VM Ware, VM /370, VM/CMS

Review of Operating System Concepts 78


Review of Operating System Concepts 79
Review of Operating System Concepts 80
Synchronization
What is a process?
Concurrent processes
The critical section problem
Other synchronization problems
Language mechanisms for synchronization

Review of Operating System Concepts 81


Concurrent Processes
Concurrency - simultaneous execution of multiple threads of
control
concurrency appears in:
mutiprogramming - management of multiple processes on a uniprocessor
architecture
mutliprocessing - management of multiple processes on a multiprocessor
architecture
distributed computing - management of multiple processes on multiple
independent computers

Synchronization using atomic (indivisible) operations to ensure


cooperation between threads

Race Condition - the outcome of the multiple process execution


depends on the order of the execution of the instructions of the
processes

Review of Operating System Concepts 82


Concurrent Processes (cont.)
Two processes are concurrent if their execution can
overlap in time
Multiprocessor systems
Different processors executing different processes
Uniprocessor systems
Time-slicing, or interleaving computations and I/O
Two processes are serial if one must complete before
the other begins
Concurrent processes normally interact either through
shared variables or through message passing
If two processes dont interact, they are transparent to
each other (we do not care)

Review of Operating System Concepts 83


Concurrent Processes (cont.)
Thread A Thread B
i=0 i=0
while (i < 10) while (i > 10)
i=i+1 i=i1
print A wins print B wins

Assumptions:
Memory load and store are atomic
Increment and decrement at not atomic

Questions:
Who wins?
Is it guaranteed that someone wins?
What if both threads have their own CPU, running concurrently at exactly the same speed? Is
it guaranteed that it goes on forever?
What if they are sharing a CPU?

Review of Operating System Concepts 84


Solution to Critical-Section Problem

Mutual Exclusion - If process Pi is executing in its critical section,


then no other processes can be executing in their critical sections

Progress - If no process is executing in its critical section and there


exist some processes that wish to enter their critical section, then
the selection of the processes that will enter the critical section
next cannot be postponed indefinitely

Bounded Waiting - A bound must exist on the number of times


that other processes are allowed to enter their critical sections after
a process has made a request to enter its critical section and before
that request is granted
Assume that each process executes at a nonzero speed
No assumption concerning relative speed of the N processes

Review of Operating System Concepts 85


Solutions to Critical-Section Problems
Busy waiting
Disabling interrupts
Test-and-set
Swap
Binary semaphores

Review of Operating System Concepts 86


Other Synchronization Problems
Dining Philosophers Problem
N Processes, N resources, a process requires two adjacent resources to execute
Care must be taken to avoid starvation and deadlock

Producer-Consumer Problem
A set of producer processes supplies input to a set of consumer processes
Producers cannot produce if there is no space
Consumers cannot consume if there is no input
Two producers should not fill the same space and consumers should not consume the same
input

Readers-Writers Problem
Shared data exists
Either one writer or multiple readers can access it at one time
Writers priority gives priority to arriving writers over waiting readers
Readers priority gives priority to arriving readers over waiting writers

Review of Operating System Concepts 87


Deadlock
Deadlock occurs when a set of processes in a
system is blocked waiting on requirements
that can never be satisfied

Review of Operating System Concepts 88


Deadlock
A wait-for-graph (WFG) can be used to represent
the state of a system

The nodes in the graph represent processes, and


a directed edge between nodes means that the
process at the tail of the edge is waiting for a
resource held by the process at the head

A cycle in the WFG indicates a deadlock

Review of Operating System Concepts 89


Deadlock

Review of Operating System Concepts 90


Deadlock vs. Starvation
Starvation occurs when a process waits for a resource that
is repeatedly available but is never assigned to the waiting
process

Two differences between deadlock and starvation


With starvation, it is not certain that a process will never get the
resource. With deadlock, a process is blocked forever (absent
outside intervention)
With starvation, the requested resource is used continuously;
with deadlock, it is idle

Recall the readers-writers problem as an example of


starvation

Review of Operating System Concepts 91


Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously.
Four necessary conditions for deadlock to occur:
Mutual exclusion: only one process at a time can use a
resource
Hold and wait: a process holding at least one resource is
waiting to acquire additional resources held by other processes
No preemption: a resource can be released only voluntarily by
the process holding it, after that process has completed its task
Circular wait: there exists a set {P0, P1, , P0} of waiting
processes such that P0 is waiting for a resource that is held by
P1, P1 is waiting for a resource that is held by P2, , Pn1 is
waiting for a resource that is held by Pn, and P0 is waiting for a
resource that is held by P0.

Review of Operating System Concepts 92


Deadlock Handling Strategies
Deadlock Prevention
Ensure that at least one of the four necessary conditions cannot hold.
For example, do not allow a process to hold resources and ask for others
Design time

Deadlock Avoidance
Check each resource request and make sure that granting it will not cause deadlock.
The Bankers Algorithm is an example of deadlock avoidance
Run-Time

Deadlock Detection and Recovery


Periodically check the state of the system and look for a deadlock.
If one is present, break it, typically by aborting processes

Ignore It

Review of Operating System Concepts 93


Computing Environments
Traditional computer
Blurring over time
Office environment
PCs connected to a network, terminals attached to
mainframe or minicomputers providing batch and
timesharing
Now portals allowing networked and remote systems access
to same resources
Home networks
Used to be single system, then modems
Now firewalled, networked

Review of Operating System Concepts 94


Computing Environments (Cont)
Client-Server Computing
Dumb terminals supplanted by smart PCs
Many systems now servers, responding to requests generated by
clients
Compute-server provides an interface to client to request
services (i.e. database)
File-server provides interface for clients to store and retrieve
files

Review of Operating System Concepts 95


Peer-to-Peer Computing
Another model of distributed system

P2P does not distinguish clients and servers


Instead all nodes are considered peers
May each act as client, server or both
Node must join P2P network
Registers its service with central lookup service on network,
or
Broadcast request for service and respond to requests for
service via discovery protocol
Examples include Napster and Gnutella

Review of Operating System Concepts 96


Web-Based Computing
Web has become ubiquitous
PCs most prevalent devices
More devices becoming networked to allow
web access
New category of devices to manage web
traffic among similar servers: load balancers
Use of operating systems like Windows 95,
client-side, have evolved into Linux and
Windows XP, which can be clients and servers
Review of Operating System Concepts 97
Motivation for Advanced Operating
Systems
Early OS design focused on traditional OS,
running large, uniprocessor systems
The 1970s and 1980s saw huge gains in
processor and network technology
Economies of scale lead to multiprocessor
systems
Conventional OSs are insufficient for the task

Therefore, research into advanced OS design was


(and still is) needed

Review of Operating System Concepts 98


Types of Advanced Operating Systems
Distributed Operating Systems
Loosely-coupled systems (no shared memory or clock)
Spatially separated processes
Interconnection network
Typically a set of workstations or LAN or WAN

Multiprocessor (Parallel) OS
Tightly-coupled systems (shared memory, clock, often bus-
based)
Spatially adjacent processors
Interconnection network
Typically a bunch of mP in a box

Review of Operating System Concepts 99


Types of Advanced Operating Systems
(cont.)
Database OS
Special purpose to support database operations
Transactions
Facilities for concurrency control
Failure recovery
Airline reservations, credit card transactions, stock market

Real-Time OS
Not time-sharing (non-interactive)
A set of jobs, each with a deadline
OS provides guarantees that jobs will finish by deadline
Factory floor automation, safety sytems

Multimedia OS

Review of Operating System Concepts 100

You might also like