Professional Documents
Culture Documents
7 SCHEDULING 06 Dec 2019material - IV - 06 Dec 2019 - OS - L6 - Scheduling 1 - 2017
7 SCHEDULING 06 Dec 2019material - IV - 06 Dec 2019 - OS - L6 - Scheduling 1 - 2017
LECTURE - 6
SCHEDULING ALGORITHMS
Policies:
▪ Priority Scheduling
(Non – Preemptive)
EXAMPLE - 1
0 P1 5
Time required by
0 P2 10 CPU to execute job
0 P3 8
0 P4 3
P1 P2 P3 P4
0 5 15 23 26
Gantt Chart
Average Waiting Time:
P1 => 0 – 0 = 0
P2 => 5 – 0 = 5
P3 => 15 – 0 = 15
P4 => 23 – 0 = 23
P1 = 5 – 0 = 5
P2 = 15 – 0 = 15
P3 = 23 – 0 = 23
P4 = 26 – 0 = 26
P1 => 0 – 0 = 0
P2 => 5 – 0 = 5
P3 => 15 – 0 = 15
P4 => 23 – 0 = 23
Cons:
▪ Short job have to wait for long time, when the CPU is allocate
to long jobs
EXAMPLE - 2
0 P1 3
2 P2 6
4 P3 4
6 P4 5
8 P5 2
P1 P2 P3 P4 P5
0 3 9 13 18 20
Gantt Chart
Shortest Job First Scheduling [SJF]
▪ If two process have the same CPU time, then FFCS is used
0 P1 5
0 P2 10
0 P3 8
0 P4 3 Shortest CPU time
P4 P1 P3 P2
0 3 8 16 26
Gantt Chart
Pros:
Cons:
0 P1 3
2 P2 6
4 P3 4
6 P4 5
8 P5 2
P1 P2 P3 P5 P2 P4
0 3 4 8 10 15 20
Gantt Chart
Priority Scheduling
=> Preemptive
Cons:
▪ Low priority jobs are waiting for the CPU for the longest period of
the time (AGING)
EXAMPLE
3 P1 5
2 P2 10
4 P3 8
1 P4 3
P4 P2 P1 P3
0 3 13 18 26
Gantt Chart
Round Robin Scheduling
▪ CPU time is divided into Time Slices (or) Time Quantum, Each
process is allocated a small time slice
Time Quantum = 2 ms
Gantt Chart
Waiting Time:
P1 = (0-0)+ (9-2) = 7
P2 = (2-1) + (10-4) + (14-12) = 9
P3 = (4-3) + (12-6) + (15-14) = 8
P4 = (6-6) = 0
P5 = (8-7) = 1
P1 = 10 – 0 = 10
P2 = 15 – 1 = 14
P3 = 17 – 3 = 14
P4 = 8 – 6 = 2
P5 = 9 – 7 = 2
P1 24
P2 3
P3 3
Time Quantum = 4 ms
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Gantt Chart
Arrival Service
Process Time Time
1 0 3
2 2 6
3 4 4
4 6 5
5 8 2
Example of RR with Time Quantum = 20
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Response Ratio = W + S / S
Three queues:
Q2 – FCFS
Scheduling: