0% found this document useful (0 votes)
152 views

Scheduling Algorithm Dsatm PDF

The document discusses process scheduling problems and solutions. It provides examples of processes with arrival times and burst times. It draws Gantt charts and calculates waiting times and turnaround times for the examples under FCFS, SJF, priority, and round robin scheduling schemes. The key metrics like average waiting time and average turnaround time are computed and compared for each scheduling scheme.

Uploaded by

M.A raja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Scheduling Algorithm Dsatm PDF

The document discusses process scheduling problems and solutions. It provides examples of processes with arrival times and burst times. It draws Gantt charts and calculates waiting times and turnaround times for the examples under FCFS, SJF, priority, and round robin scheduling schemes. The key metrics like average waiting time and average turnaround time are computed and compared for each scheduling scheme.

Uploaded by

M.A raja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Operating Systems Module 2 17CS64

PROCESS SCHEDULING PROBLEMS


1. Consider the following set of processes:

Arrival time Burst time


Process
P1 0 6
P2 2 3
P3 4 3
P4 5 5
i) Draw Gantt charts showing the execution of these processes using FCFS, preemptive
SJF/SRTF, non-preemptive SJF and RR (Quantum – 1 and Quantum=2) scheduling
schemes.
ii) Compute the turnaround time and waiting time for each process for each of schemes above.
iii) Compute the average turnaround time and average waiting time in each scheme and above.

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

b) pre-emptive SJF/ SRTF


Gantt chart
P1 P2 P3 P1 P4
0 2 5 8 12 17
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
P1 12-6=6 P1 12-0=12
P2 3-3=0 P2 5-2=3
P3 4-3=1 P3 8-4=4
P4 12-5= 7 P4 17-5=12
Avg Waiting Time (6+0+1+7)/4= 3.5 ms Avg TAT (12+3+4+12)/4= 7.75 ms

c) Non pre-emptive SJF


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 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

Gantt chart (quantum=2)

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

b) Preemptive priority Scheduling algorithm:


Gantt chart
J1 J3 J1 J4 J2
0 3 6 9 14 19
Waiting Time Turnaround Time
Process TAT-BT Process C.T- A.T
J1 9-6=3 J1 9-0=9
J2 16-5=11 J2 19-3=16
J3 3-3=0 J3 6-3=3
J4 9-5= 4 J4 14-5=9
Avg Waiting Time (3+11+0+4)/4= 4.5 ms Avg TAT (9+16+3+9)/4= 9.25 ms

3. Consider the following set of processes:


Process Burst time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
The processes are assumed to have arrived in the order P1 P2 P3 P4 P5 all at time 0.
i) Draw Gantt charts showing the execution of these processes using FCFS, SJF, priority (highest
priority=1)and RR (Quantum – 1) scheduling schemes
ii) Compute the turnaround time and waiting time for each process for each of schemes above.
iii) Compute the average turnaround time and average waiting time for each process for each of schemes
above.

Soln: a) FCFS:
Gantt chart
P1 P2 P3 P4 P5
0 10 11 13 14 19

Page 5
Operating Systems Module 2 17CS64

Waiting Time Turnaround Time


Process TAT-BT Process C.T- A.T
P1 10-10=0 P1 10-0=10
P2 11-1=10 P2 11-0=11
P3 13-2=11 P3 13-0=13
P4 14-1= 13 P4 14-0=14
P5 19-5= 14 P5 19-0=19
Avg WT (0+10+11+13+14)/5= 4 ms Avg TAT (10+11+13+14+19)/5= 8.25 ms

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

Waiting Time Turnaround Time


Process TAT-BT Process C.T- A.T
P1 16-10=6 P1 16-0=16
P2 1-1=0 P2 1-0=1
P3 18-2=16 P3 18-0=18
P4 19-1= 18 P4 19-0=19
P5 6-5= 1 P5 6-0=6
Avg WT (6+0+16+18+1)/5= 8.2 ms Avg TAT (16+1+18+19+6)/5= 12 ms

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

Waiting Time Turnaround Time


Process TAT-BT Process C.T- A.T
P1 19-10=9 P1 19-0=19
P2 2-1=1 P2 2-0=2
P3 7-2=5 P3 7-0=7
P4 4-1= 3 P4 4-0=4
P5 14-5= 9 P5 14-0=14
Avg WT (9+1+5+3+9)/5= 5.4 ms Avg TAT (19+2+7+4+14)/5= 9.2 ms

Page 7
Operating Systems Module 2 17CS64

4. Consider the following set of processes.

Burst time Arrival Time Priority


Process
P1 10 0 3
P2 1 0 1
P3 2 3 3
P4 1 5 4
P5 5 10 2

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

Waiting Time Turnaround Time


Process TAT-BT Process C.T- A.T
P1 10-10=0 P1 10-0=10
P2 11-1=10 P2 11-0=11
P3 10-2=8 P3 13-3=10
P4 9-1= 8 P4 14-5=9
P5 9-5= 4 P5 19-10=9
Avg WT (0+10+8+8+4)/5= 6 ms Avg TAT (10+11+10+9+9)/5= 9.8 ms

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

5. Consider the following data about processes.


Process Arrival time Burst time
P0 0 6
P1 1 3
P2 2 1
P3 3 4

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

Waiting Time Turnaround Time


Process TAT-BT Process C.T- A.T
P0 14-6=8 P0 14-0=14
P1 4-3=1 P1 5-1=4
P2 1-1=0 P2 3-2=1
P3 6-4= 2 P3 9-3=6
Avg WT (8+1+0+2)/4= 2.75 ms Avg TAT (14+4+1+6)/4= 6.25 ms

Page 10
Operating Systems Module 2 17CS64

6. Consider the following data about processes.

Process Burst time Arrival time


P0 10 0
P1 29 1
P2 3 2
P3 7 3

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

You might also like