Week 5a
Week 5a
Week 5a
Scheduling Algorithms
P1 24
P2 3
Suppose that the processesP3 3
arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
P1
0 P2 24 27
30
Waiting time for P1
P3 = 0; P2 =
24;
Average waiting time: P3 = 27
(0 + 24 + 27)/3
= 17
FCFS Scheduling (Cont)
Suppose that the processes arrive in the order
P 2 , P 3 , P1
The Gantt chart for the schedule is:
P2 P3 P1
0 3 30
6
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
Task (FCFS)
Process or Task Time units
A 8
B 4
C 9
D 5
0.0
P2 8
0.0 chart
SJF scheduling
P3arrive at the same time ( time 0) 7
Assuming all
0.0 P3 P2
P4 P1
P4 3
0 3
0.0 9 16 24
P1 P4 P3 P2
6 9
0
Average waiting time = (0+ (16-2) + (9-4) + 16 24
(6-5)) / 4 = (14+5+1)/4 =5 ms
Average turnaround time = (6+ (24-2) + (16-4) + (9-5)) = 44/4 = 11
ms
Shortest Remaining Time First Scheduling
P1
P2 P4 P1 P3
1 5 10
0 17 26
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Average wait time = ((10-4) + 4+ 7) = 17/3 = 5.66 ms
Typically, higher average turnaround than SJF, but better response
Example Task