Вы находитесь на странице: 1из 15

Operating

Systems
Lecture 15
Agenda for Today
 Review of previous lecture
 Shortest-job-first

 Round-Robin scheduling

 Multi-level queues scheduling

 Multi-level feedback queues


scheduling
 Recap of lecture
14 September 2019 © Copyright Virtual University of
Pakistan
Review of Lecture 14
 Short-term scheduler
 Dispatcher

 Reasons for invoking scheduler


 Preemptive and non-preemptive
schedulers
 Optimization criteria

 FCFS
14 September 2019 © Copyright Virtual University of
Pakistan
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.
14 September 2019 © Copyright Virtual University of
Pakistan
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.
14 September 2019 © Copyright Virtual University of
Pakistan
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 P P P 1P 3 2 4

0 7 12 16

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


14 September 2019 © Copyright Virtual University of
Pakistan
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

14Average
September 2019
waiting time = (9 + 1
© Copyright Virtual University of
+ 0 +2)/4 = 3
Pakistan
SJF—CPU Burst of a
Process
 Can only estimate the length
of the next CPU burst.
 Can be done by using the
length of previous CPU
bursts, using exponential
averaging.
14 September 2019 © Copyright Virtual University of
Pakistan
Exponential Averaging

 Estimation based on historical data


 tn = Length of nth CPU burst
 n+1 = Estimate for n+1 st CPU burst
 , 0 ≤  ≤1

n+1 = tn + (1- ) n


14 September 2019 © Copyright Virtual University of
Pakistan
Exponential Averaging
 Plugging in value for n, we get
n+1 = tn + (1- )[tn-1 + (1- )n-1]
= tn + (1- )tn-1 + (1- )2n-1
 Continuing like this results in
n+1 =  tn+ (1 - )  tn-1 + …
+ (1 - )j  tn-j + …
+ (1 - )n+1 0
14 September 2019 © Copyright Virtual University of
Pakistan
Exponential Averaging
 If  = 0
 n+1 = n
 Actual previous bursts do not
count
 If  = 1
 n+1 = tn
 Estimates do not count
14 September 2019 © Copyright Virtual University of
Pakistan
Exponential Averaging
 Typical value used for  is ½.
With this value, our n+1st

estimate is

n+1 = tn/2 + tn-1/22 + tn-2/23 + tn-3/24 + …

 Hence the name exponential


averaging
14 September 2019 © Copyright Virtual University of
Pakistan
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
14 September 2019 © Copyright Virtual University of
Pakistan
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.
14 September 2019 © Copyright Virtual University of
Pakistan
Recap of Lecture
 Shortest-Job-First (SJF)
 Shortest-Remaining-Time-First
(SRTF)
 Exponential averaging

 Priority scheduling

 Recap of lecture
14 September 2019 © Copyright Virtual University of
Pakistan

Вам также может понравиться