You are on page 1of 65

What is an Operating System?

User programs

OS Interface (e.g., System calls or APIs)*

Operating System

Hardware Interface (e.g., Machine language)

Hardware

* (1) API: Application Program interface like web browser, text editor etc.,
(2) System Call: Process request for a specific service
°efinition:

A program that acts as an intermediary between a user of


a computer and the computer hardware.
 OS acts as an extended machine: Hides the messy details
which must be performed. Presents user with a Virtual
machine, easier to use
 It is a resource manager. Each program gets time and
space with the resource
þoals:

Execute user programs

Solve user problems easily

Make the system convenient to use

Use hardware in an efficient way


Concepts:
Process: Program in execution. OS has all information
about each process.

°eadlocks: Two or more processes interacting with each


other waiting for resources indefinitely

Files: Files are grouped together as directories. System calls


for Reading/Writing/Closing/Creating a file is done by OS

Memory Management: Multiple programs in memory at the


same time without interfering with one another

Security: OS to manage the system security so that data is


accessible to authorized to users
History of Operating Systems

 First generation 1945 - 1955


è Technology: =  
  

     

v
è Programming:   
è Programming language:     
è Tasks:      
è OS:  
 Computer designer is:
è builder and
è programmer and
è operator and
è ³sys admin´
History of Operating Systems

r Second generation 1955 ± 19v5


è Technology: h  
è Programming:  
è Programming languages: Ä h  
è Tasks: ?
è Computer: á  
è OS:   

r Universities started to buy computers (millions $)

r Separation between computer designers, builders,


operators, programmers and maintenance personnel.
[
¢    ?

User °ata

Tape User program


Tape

System
Program

OS

Card Tape Compute Tape Printer


Reader
Input Output
History of Operating Systems

 Third generation 19v5 ± 19[

± Technology: à  

± Programming:  

± Programming languages: Ä h  

± Tasks: ?  

± Computers: à á¢ 

± OS: á 
     

 OSes °eveloped:

± MULTICS (father of all modern OSes)

± UNIX (System V, BS°)

± POSIX (by IEEE)

± MINIX (by Tanenbaum)

± Linux (originated by Linus Torvalds, inspired


by MINIX)
History of Operating Systems

 Fourth generation 19[ -Present

è Technology: ð ?à

è Programming: m  =

è Programming languages:   = 

è Computer: 

è OS: — á  ? 

 Cheap PCs
Types of Operating Systems

 Mainframe operating systems


è Room-size computers
è High I/O capacity
è Offers:
r Batch processing (no interaction, such as large
reports)
r Transaction processing (large number of small
requests)
r Timesharing (multiple users sitting in front of
clients)
Types of Operating Systems
 Server operating systems

è Offer services like print, file, or web

è UNIX, Windows 2 , Linux

 Multiprocessor operating systems

è Parallel computing

 Personal computer operating systems

è Single user with a good þUI, such as Windows 9[,


Windows 2 , Macintosh OS, Linux
 Real-time operating systems
è E.g. industrial process control systems where each job
must be completed in the specified time.
è Hard real-time (nuclear reactor control systems) or
soft-real time systems (e.g multimedia systems)
depending on the acceptance of missing deadlines
 Embedded operating systems:
è Real-time systems with some resource constraints like
memory, CPU, power.
 Smart card operating systems
è Extremely primitive OS running on credit card-sized
devices with a CPU.
OPERATINþ SYSTEM STRUCTURES
Monolithic STRUCTURE:

Application Programming

System Programming

MS-°OS °rivers

ROM - BIOS °evice °rivers


Collection of procedures, well-defined with
parameters and results
All functions are linked into huge OS
No information hiding

Advantage:
Better application performance

°isadvantage:
All layers can touch the hardware.
Modifying a procedure can introduce bugs in
unrelated parts of the system
Layered Structure:
Application Application
Program Program
User mode

Kernel mode
System Services

File System

Memory and I/O device management

Processor Scheduling

Hardware
Components are organized as modules
Each module provides a set of functions which can be called
by other module
Hierarchical organization of modules
Lower layers can be invoked by higher layers, vice-versa is
not true
Advantages:
Each layer of code is given access to only the lower level
interfaces it requires
One layer can be replaced without affecting other parts of the
system
°isadvantage:
Low application performance in comparison to monolithic
structure
Virtual Machine:
Non-Virtual machine Virtual machine
VMWare Structure:
Resources of the physical machine are shared

Useful for running different OS simultaneously

Protection is excellent, sharing is not possible

OS creates an illusion of multiple processes, each


executing on its own processor with its own (virtual)
memory

Time multiplexing of CPU, I/O devices

Space multiplexing of memory, disk


Exokernel Structure:
Application Application Application Application
Code Code Code Level

User-
Operating Operating Operating Level
System System System

Resource Multiplexer Exokernel

Memory CPU Network °isk TLB


Hardware

Kernel Level
Resource multiplexing: Individual disk blocks, not
disk partitions

Each user gets a subset of resources

Exokernel allocates resources to virtual machines

Each VM can run its own OS, except that each one
is restricted to using the resources: asked for and been
allocated
Client Server or Microkernel Structure:

Process
Client Application File Server Memory Server
Server User
Mode

Kernel
Mode
Microkernel

Hardware Send
Reply
Moves code from kernel to user space
User modules communicate using message passing
User process (client process) sends a request to the
server process. Server process does the work and
sends the response
Kernel handles the communication between the
client and the server (Validates messages, passes
them between the components and grants access to
hardware)
Advantage:
Easier to port the OS to new architecture
More reliable and secure
Architecture of Unix System:

emacs

sh who
Kernel date

ed
cc Hardware
wc

grep

Other apps
UNIX ARCHITECTURE

Typical computer system consists of:

rHardware

rOperating system

rApplications and utilities

Typical OS includes a user interface or a 




Unix is somewhat unique in that the command interpreter is


p  integrated with the OS but is a separate program
Block °iagram of System Kernel
User Programs
Libraries
User Level
Kernel
Level System Call Interface

Inter-process
File Subsystem Process communication

control
Scheduler
subsystem
°evice drivers
Memory
management

Hardware control

Hardware
Hardware Level
User Process Layer

 The uppermost layer consists of user processes running:


r Shells
r Unix commands
r Utility programs
r User application programs
 User processes:
r Protected from from other users
r Have no access to Unix kernel routines except through the
system call interface
r Cannot directly access kernel memory space
Kernel Services Layer

 The next level provides all the kernel services


è Mapping between user requests and device driver actions
è The user system call is converted to a kernel service call that
actually performs the requested service
r Process creation and termination
r I/O services
r File/disk access services
r Terminal handling services
System Call Interface Layer

 The system call interface layer converts a process running in


user mode to a protected kernel mode process

è This allows the program to invoke protected kernel routines


to perform system functions
Unix Command Interface and Commands

 Unix command interface is a separate program referred to as the


shell
 The shell provides the user interface between the user and the
kernel
 Unix commands and utilities, like the shell, are also separate
programs
 They are part of a Unix distribution, and are considered part of
Unix but p  part of the kernel
Some System Calls For Process Management
Some System Calls For File Management
Some System Calls For °irectory
Management
Some System Calls For Miscellaneous Tasks
System Calls
PROCESS MANAþEMENT
 A
  is a
   in execution: (A program is passive, a process
active.)

 A process has resources (CPU time, files) and attributes that must be
managed.

 Management of processes includes:

r Process Scheduling (priority, time management, . . . )


r Creation/termination
r Block/Unblock (suspension/resumption )
r Synchronization
r Communication
r °eadlock handling
r °ebugging
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
Process Life Cycle

new terminated
admitted scheduled
ready running exit, kill

interrupt/yield

event wait for event


occurrence blocked

event: an interrupt or a signal from another process


The Scheduler

 A module in OS to execute scheduling decisions.

 This is done by:

r switching context

r switching to user mode

r jumping to the proper location in the user program to


restart that program
Scheduling: °eciding which process should run and
for how long

°ispatcher: Switches the processor from one process


to another

Scheduler selects the process, dispatcher gives control


to the process selected

°ispatch Latency: Time taken for the dispatcher to


stop one process and start another running
Scheduling Algorithms:
Types of Schedulers
 Long-term scheduler:
è admits new processes to the system;
è required because each process needs a portion of the
available memory for its code and data.
 Medium-term scheduler:
è is not found in all systems;
è required to control the temporary removal from
memory of a process when the latter is extractable.
 Short-term scheduler:
è determines the assignment of the CPU to ready
processes;
è required because of IO requests and completions.
Terminology: Preemptive vs. Non-Preemptive

 Preemptive: A Process can be suspended and resumed


 Non-preemptive: A process runs until it voluntarily gives up the
CPU (waiting on I/O or terminate).
 Most modern OSs use preemptive CPU scheduling, implemented
via timer interrupts.
 Non-preemptive is used when suspending a process is
impossible or very expensive
e.g., can¶t ³replace´ a flight crew in middle of flight.
Scheduling Criteria
 CPU utilization: Keep the CPU as busy as possible (from
 to 1 )
 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
Optimization Criteria

 Max CPU utilization

 Max throughput

 Min turnaround time

 Min waiting time

 Min Response time


Scheduling Performance Metrics
 Batch Systems: No users impatiently waiting for a quick
response (reduces process switches and improves
performance)
è Max Throughput
è Min Turnaround time
è Max CPU utilization
 Interactive Systems: User interaction, hence preemption is
essential
è Response time: Respond to requests quickly
Time between issuing a command and getting the result
è Proportionality: Simple jobs should complete faster,
complex jobs can take a long time
Scheduling Policies
 Batch systems:
r First Come First Served
r Shorted Job First
r Shortest Remaining Time Next
 Interactive systems:
r Round Robin
r Priority Scheduling
r Multiple Queues
r Shortest Process Next
r þuaranteed Scheduling
r Lottery Scheduling
r Fair-share Scheduling
First Come First Serve Scheduling (FCFS)

Process Burst time


P1 24
P2 3
P2 3
First Come First Serve Scheduling

 The average of waiting time in this policy is usually quite


long

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

 Average waiting time= ( 2427)/3=17


First Come First Serve Scheduling

 Suppose we change the order of arriving job P2, P3, P1


First Come First Serve Scheduling

 Consider if we have a CPU-bound process and many I/O-


bound processes

 There is a  =  as all the other processes waiting


for one of the big process to get off the CPU

 FCFS scheduling algorithm is non-preemptive


Short job first scheduling (SJF)

 This algorithm associates with each process the length of


the processes¶ next CPU burst

 If there is a tie, FCFS is used

 In other words, this algorithm can be also regard as


shortest-next-cpu-burst algorithm

 SJF is optimal ± gives minimum average waiting time for a


given set of processes
Example
Processes Burst time
P1 v
P2 [
P3 7
P4 3

FCFS average waiting time: ( v1421)/4=1 .25


SJF average waiting time: (31v9 )/4=7
Short job first scheduling

Two schemes:

 Non-preemptive: once CPU given to the process it cannot


be preempted until completes its CPU burst

 Preemptive: if a new process arrives with CPU burst length


less than remaining time of current executing process,
preempt. This scheme is know as the Shortest-Remaining-
Time-First (SRTF)
Short job first scheduling- Non-preemptive
Short job first scheduling- Preemptive
Priority Scheduling

 A priority number (integer) is associated with each process


The CPU is allocated to the process with the highest priority
(smallest integer Ł highest priority)
r Preemptive
r Non-preemptive

 SJF is a special priority scheduling where priority is the


predicted next CPU burst time, so that it can decide the
priority
Priority Scheduling

Processes Burst time Priority Arrival time


P1 1 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
The average waiting time=(v 1v1[1)/5=[.2
Priority Scheduling

Processes Burst time Priority Arrival time


P1 1 3 .
P2 1 1 1.
P3 2 4 2.
P4 1 5 3.
P5 5 2 4.

þantt chart for both preemptive and non-preemptive, also


waiting time
Priority Scheduling

Problem : Starvation ± low priority processes may never


execute

Solution : Aging ± as time progresses increase the priority of


the process
Round-Robin Scheduling

 The Round-Robin is designed especially for time sharing


systems.

 It is similar FCFS but add preemption concept

 A small unit of time, called   , is defined

 Each process gets a small unit of CPU time (


 ), usually 1 -1 milliseconds. After this time has
elapsed, the process is preempted and added to the end of
the ready queue.
Round-Robin Scheduling
Round-Robin Scheduling

 If there are processes in the ready queue and the time


quantum is , then each process gets 1/of the CPU time
in chunks of at most time units at once. No process waits
more than (-1) time units.
 Performance:
r large => FIFO
r small => must be large with respect to context
switch, otherwise overhead is too high
 Typically, higher average turnaround than SJF, but better

 

You might also like