You are on page 1of 17

Operating

Systems
Lecture 11
Review of Lecture 14
 Short-term scheduler
 Dispatcher
 Reasons for invoking scheduler
 Preemptive and non-preemptive
schedulers
 Optimization criteria
 FCFS
Agenda for Today
 Review of previous lecture
 Shortest-job-first
Shortest-Job-First (SJF)
Scheduling
 Process with the shortest CPU
burst is scheduled first.
 Non-preemptive – once CPU
given to a process it cannot be
preempted until completes its
CPU burst.
Shortest-Job-First (SJF)
Scheduling
 Preemptive – if a new process arrives
with CPU burst length less than
remaining time of current executing
process, preempt it—Shortest-
Remaining-Time-First (SRTF).
 SJF is optimal non-preemptive
scheduling algorithm – gives minimum
average waiting time for a given set of
processes.
Non-Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
Gantt chart P1 P3 P2 P4

0 7 12 16

Average waiting time = (0+6+3+7)/4 = 4


Preemptive SJF
 Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 Gantt chart P1 P2 P3 P2 P4 P1

0 2 4 5 7 11 16

 Average waiting time = (9 + 1 + 0 +2)/4 = 3


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).
Preemptive
Non-preemptive
Priority Scheduling
SJF is a priority scheduling where
priority is the predicted next CPU
burst time.
Problem  Starvation – low priority
processes may never execute.
Solution  Aging – as time
progresses increase the priority of
the process.
SJF is Optimal
 Logical Argument: Decrease in
the wait times for short processes
is much more than increase in the
wait times for long processes
P1 P2 P3
5 3 2

P3 P2 P1
2 3 5
Round Robin (RR)
 Each process gets a small unit
of CPU time, called time slice or
quantum, which is usually 10-
100 milliseconds. After this
time has elapsed, the process
is preempted and added to the
end of the ready queue.
Round Robin (RR)
 If there are n processes in the
ready queue, the time quantum
is q, and context switch time is
tcs, then no process waits more
than (n-1)(q+tcs) time units
 Used in time-sharing systems
where response time is an
important performance criteria
Round Robin (RR)
Performance
 q large  FCFS
 q small  q must be large with
respect to context
switch, otherwise overhead
is too high.
Round Robin Example
Process Burst Time
P1 53 — 33 — 13
P2 17
P3 68 — 48 — 28 — 8
P4 24 — 4
The Gantt chart with quantum 20 is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162


Round Robin Example
Process Turnaround TimeWaiting Time
P1 134 134 – 53 = 81
P2 37 37 – 17 = 20
P3 162 162 – 68 = 94
P4 121 121 – 24 = 97
Average waiting time = 73
Average waiting time for SJF = 38
Typically, higher average turnaround
than SJF, but better response.
Quantum vs Context
Switch

Process Time = 10 Quantum Context


Switches
12 0

6 1

1 9
Turnaround Time vs
Quantum

You might also like