Scheduling Algorithm Dsatm PDF
Scheduling Algorithm Dsatm PDF
Soln: a) FCFS:
Gantt chart
P1 P2 P3 P4
0 6 9 12 17
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 6-6=0 P1 6-0=6
P2 7-3=4 P2 9-2=7
P3 8-3=5 P3 12-4=8
P4 12-5= 7 P4 17-5=12
Avg Waiting Time (0+4+5+7)/4= 4 ms Avg TAT (6+7+8+12)/4= 8.25 ms
Page 1
Operating Systems Module 2 17CS64
Page 2
Operating Systems Module 2 17CS64
d) Round Robin
Gantt chart (quantum=1)
P1 P1 P2 P1 P2 P3 P1 P4 P2 P3 P1 P4 P3 P1 P4 P4 P4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Quantum=1
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 14-6=8 P1 14-0=15
P2 7-3=4 P2 9-2=7
P3 9-3=6 P3 13-4=9
P4 12-5= 7 P4 17-5=12
Avg Waiting Time (8+4+6+7)/4= 6.25 ms Avg TAT (14+7+9+12)/4= 10.5 ms
P1 P2 P1 P3 P2 P4 P1 P3 P4
0 2 4 6 8 9 11 13 14 17
Quantum=2
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 13-6=7 P1 13-0=13
P2 7-3=4 P2 9-2=7
P3 10-3=7 P3 14-4=10
P4 12-5= 7 P4 17-5=12
Avg Waiting Time (7+4+7+7)/4= 6.25 ms Avg TAT (13+7+10+12)/4=10.5 ms
Page 3
Operating Systems Module 2 17CS64
2. Consider the following data about processes. A larger priority number has a higher
priority
Arrival Burst Priority
Jobs time time
J1 0 6 4
J2 3 5 2
J3 3 3 6
J4 5 5 3
Draw Gantt Chart and calculate waiting time and turn around time using
a. FCFS
b. Preemptive priority Scheduling algorithm.
Soln: a) FCFS:
Gantt chart
J1 J2 J3 J4
0 6 11 14 19
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
J1 6-6=0 J1 6-0=6
J2 8-5=3 J2 11-3=8
J3 11-3=8 J3 14-3=11
J4 14-5= 9 J4 19-5=14
Avg Waiting Time (0+3+8+9)/4= 5 ms Avg TAT (6+8+11+14)/4= 9.75 ms
Page 4
Operating Systems Module 2 17CS64
Soln: a) FCFS:
Gantt chart
P1 P2 P3 P4 P5
0 10 11 13 14 19
Page 5
Operating Systems Module 2 17CS64
b) SJF:
Gantt chart
P2 P4 P3 P5 P1
0 1 2 4 9 19
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 19-10=9 P1 19-0=19
P2 1-1=0 P2 1-0=1
P3 4-2=2 P3 4-0=4
P4 2-1= 1 P4 2-0=2
P5 9-5= 4 P5 9-0=9
Avg WT (9+0+2+1+4)/5= 3.2 ms Avg TAT (19+1+4+2+9)/5= 7 ms
c) Priority:
Gantt chart
P2 P5 P1 P3 P4
0 1 6 16 18 19
Page 6
Operating Systems Module 2 17CS64
d) RR: (quantum=1)
Gantt chart
P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 P1 P1 P1 P1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Page 7
Operating Systems Module 2 17CS64
Draw Grant charts and calculate average waiting time average turnaround time using following CPU
scheduling algorithms. Assume High is 1 and Lowest is 4
i) FCFS
ii) Preemptive priority ( 1= HIGH Priority)
Soln: a) FCFS:
Gantt chart
P1 P2 P3 P4 P5
0 10 11 13 14 19
Page 8
Operating Systems Module 2 17CS64
b) Pre-emptive Priority:
Gantt chart
P2 P1 P5 P3 P4
0 1 11 16 18 19
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 11-10=1 P1 11-0=11
P2 1-1=0 P2 1-0=1
P3 15-2=13 P3 18-3=15
P4 14-1= 13 P4 19-5=14
P5 6-5= 1 P5 16-10=6
Avg WT (1+0+13+13+1)/5= 5.6 ms Avg TAT (11+1+15+14+6)/5= 9.4 ms
Draw Gantt Chart and calculate waiting time and turn around time using
a. SJF
b. SRTF
Soln: a) Non-Preemptive SJF:
Gantt chart
P0 P2 P1 P3
0 6 7 10 14
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
Page 9
Operating Systems Module 2 17CS64
P0 6-6=0 P0 6-0=6
P1 9-3=6 P1 10-1=9
P2 5-1=4 P2 7-2=5
P3 11-4= 7 P3 14-3=11
Avg WT (0+6+4+7)/4= 4.25 ms Avg TAT (6+9+5+11)/4= 7.75 ms
b) SRTF:
Gantt chart
P0 P1 P2 P1 P3 P0
0 1 2 3 5 9 14
Page 10
Operating Systems Module 2 17CS64
Draw Gantt Chart and calculate waiting time and turn around time using
a) FCFS
b) SJF
c) RR(quantum=10)
Soln: a) FCFS:
Gantt chart
P1 P2 P3 P4
0 10 39 42 49
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 10-10=0 P1 10-0=10
P2 38-29=9 P2 39-1=38
P3 40-3=37 P3 42-2=40
P4 46-7= 39 P4 49-3=46
Avg WT (0+9+37+39)/4= 21.25 ms Avg TAT (10+38+40+46)/4= 33.5 ms
Page 11
Operating Systems Module 2 17CS64
b) SJF:
Gantt chart
P1 P3 P4 P2
0 10 13 20 49
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 10-10=0 P1 10-0=10
P2 48-29=19 P2 49-1=48
P3 11-3=8 P3 13-2=11
P4 17-7= 10 P4 20-3=17
Avg WT (0+9+37+39)/4= 21.25 ms Avg TAT (10+38+40+46)/4= 33.5 ms
c) RR: (quantum=10)
Gantt chart
P1 P2 P3 P4 P2 P2
0 10 20 23 30 40 49
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 10-10=0 P1 10-0=10
P2 48-29=19 P2 49-1=48
P3 21-3=18 P3 23-2=21
P4 27-7= 20 P4 30-3=27
Avg WT (0+19+18+20)/4= 21.25 ms Avg TAT (10+48+21+27)/4= 33.5 ms
Page 12