4 Process Cpu Scheduling
4 Process Cpu Scheduling
CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
FCFS
SJF
SRTF
PRIORITY SCHEDULING
ROUND ROBIN SCHEDULING
MULTILEVEL QUEUE SCHEDULING
MULTILEVEL FEEDBACK QUEUE SCHEDULING
Objectives
Process Burst
Time
P 1 24
P 2 3
P 3 3
Suppose that the processes arrive in the
following order: P , P , P
1 2 3
P1 0 24 24 24 0
P2 0 3 27 27 24
P3 0 3 30 30 27
P1 0 24 30 30 6
P2 0 3 3 3 0
P3 0 3 6 6 3
Process No. AT BT
P1 0 4
P2 1 3
P3 2 1
P4 3 2
P5 4 5
Gantt Chart-
P1 P2 P3 P4 P5
0 4 7 8 10 15
Process No. AT BT CT TAT WT
P1 0 4 4 4 0
P2 1 3 7 6 3
P3 2 1 8 6 5
P4 3 2 10 7 5
P5 4 5 15 11 6
Average TAT=(4+6+6+7+11)/5=6.8
Average WT=(0+3+5+5+6)/5=3.8
Shortest-Job-First (SJF) Scheduling
CRITERIA:-Burst Time
MODE:-Non -preemtive
Associate with each process the length of its next
CPU burst
Use these lengths to schedule the process with the shortest
time
P1 0 6 9 9 3
P2 0 8 24 24 16
P3 0 7 16 16 9
P4 0 3 3 3 0
P.N0 AT BT
P1 1 7
P2 2 5
P3 3 1
P4 4 2
P5 5 8
Gantt chart-
P1 P3 P4 P2 P5
0 1 8 9 11 16 24
Process No. AT BT CT TAT WT
P1 1 7 8 7 0
P2 2 5 16 14 9
P3 3 1 9 6 5
P4 4 2 11 7 5
P5 5 8 24 19 11
Average TAT=(7+14+6+7+19)/5=10.6
Average WT=(0+9+5+5+11)/5=6
Example of Shortest-remaining-time-first
CRITERIA:-Burst Time
MODE:-Preemptive
Process Arrival Time
Burst Time
P 1 0 8
P 2 1 4
P 3 2 9
P 4 3 5
Preemptive SJF Gantt Chart
Process No. AT BT CT TAT WT
P1 0 8 17 17 9
P2 1 4 5 4 0
P3 2 9 26 24 15
P4 3 5 10 7 2
Average TAT=(17+4+24+7)/4=13
Average WT=(9+0+15+2)/4=6.5
Find average TAT & WT using SRTF
P.No AT BT
P1 0 8
P2 1 6
P3 2 4
P4 3 1
P5 4 5
P6 5 1
Gantt Chart-
P1 P2 P3 P4 P3 P6 P3 P2 P5 P1
0 1 2 3 4 5 6 8 13 18 25
Process No. AT BT CT TAT WT
P1 0 8 25 25 17
P2 1 6 18 17 11
P3 2 4 9 7 3
P4 3 1 4 1 0
P5 4 5 13 9 4
P6 5 1 6 1 0
Average TAT=(25+17+7+1+9+1)/6=10
Average WT=(17+11+3+0+4+0)/6=5.8
Question on SRTF
(A) 0%
(B) 10.6%
(C) 30.0%
(D) 89.4%
SOLUTION
P1 P2 P3
0 2 9 23 44 47
Process
Burst Time
Priority
P 1 10 3
P 2 1 1
P 3 2 4
P 4 1 5
P5 5 2
Priority scheduling Gantt Chart
P2 P5 P1 P3 P4
0 1 6 16 18 19
Process AT BT Priority CT TAT WT
No.
P1 0 10 3 16 16 6
P2 0 1 1 1 1 0
P3 0 2 4 18 18 16
P4 0 1 5 19 19 18
P5 0 5 2 6 6 1
Average TAT=(16+1+18+19+6)/5=12
Average WT=(6+0+16+18+1)/5=8.2
Preemtive priority Scheduling-( Smallest integer means low priority)
PNO. PRIORITY AT BT
P1 2(low priority) 0 4
P2 4 1 2
P3 6 2 3
P4 10 3 5
P5 8 4 1
P6 12(high priority) 5 4
P7 9 6 6
Gantt Chart-
P1 P2 P3 P4 P6 P4 P7 P5 P3 P2 P1
0 1 2 3 5 9 12 18 19 21 22 25
PNO. PRIORIT AT BT CT TAT WT RT
Y
25 25 21 0
P1 2 0 4
P2 4 1 2 22 21 19 0
P3 6 2 3 21 19 16 0
P4 10 3 5 12 9 4 0
P5 8 4 1 19 15 14 14
P6 12 5 4 9 4 0 0
P7 9 6 6 18 12 6 6
P1 P2 P3 P4 P6 P4 P7 P5 P3 P2 P1
0 1 2 3 5 9 12 18 19 21 22 25
Average TAT=(25+21+19+9+15+4+12)/7=15
Average WT=(21+19+16+4+14+0+6)/7=11.43
Average RT=(0+0+0+0+14+0+6)/7=2.86
Round Robin (RR)
P 3 2
P 3 3
Gantt Chart
P1 P2 P3 P1 P4 P5 P2 P6 P5 P2 P6 P5
0 2 4 6 8 9 11 13 15 17 18 19 21
PNO AT BT CT TAT WT
P1 0 4 8 8 4
P2 1 5 18 17 12
P3 2 2 6 4 2
P4 3 1 9 6 5
P5 4 6 21 17 11
P6 6 3 19 13 10
Average TAT=(8+17+4+6+17+13)/6=10.83
Average WT=(4+12+2+5+11+10)/6=7.33
Find the average TAT & WT using Round
robin with Time Quantum=4
PNO. AT BT
P1 0 4
P2 1 5
P3 2 2
P4 3 1
P5 4 6
P6 6 3
Gantt Chart
P1 P2 P3 P4 P5 P6 P2 P5
0 4 8 10 11 15 18 19 21
PNO AT BT CT TAT WT
P1 0 4 4 4 0
P2 1 5 19 18 13
P3 2 2 10 8 6
P4 3 1 11 8 7
P5 4 6 21 17 11
P6 6 3 18 13 10
Average TAT=(4+18+8+8+17+13)/6=11.33
Average WT=(0+13+6+7+11+10)/6=7.83
LJF
P1 1 ms 2 ms
P2 2 ms 4 ms
P3 3 ms 6 ms
P4 4 ms 8 ms
LRTF Example
P1 1 ms 2 ms
P2 2 ms 4 ms
P3 3 ms 6 ms
P4 4 ms 8 ms
HRRN
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is served FCFS
When it gains CPU, job receives 8 milliseconds
If it does not finish in 8 milliseconds, job is moved to
queue Q1
At Q1 job is again served FCFS and receives 16
additional milliseconds
If it still does not complete, it is preempted and
moved to queue Q2