0% found this document useful (0 votes)
12 views7 pages

CPU Scheduling Algorithms Explained

Uploaded by

selzee040
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

CPU Scheduling Algorithms Explained

Uploaded by

selzee040
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 2 Chap-2: Process Scheduling

contains a pointer to an int value that is set to the current value of the contention scope. If an
error occurs, each of these functions returns non-zero values.

Few examples on FCFS:

Completion Turn Around


Process Burst Time Arrival Start Waiting Time
Time Time
1 12 0 0 0 12 12
2 6 1 12 11 18 17
3 9 4 18 14 27 23

Gantt chart:

average waiting time: (0+11+14)/3 = 8.33ms

average turnaround time: (12+17+23) = 52/3 = 17.33ms

Another example:

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 10 0 0 0 10 10
2 29 0 10 10 39 39
3 3 0 39 39 42 42
4 7 0 42 42 49 49
5 12 0 49 49 61 61

Gantt chart:

average waiting time: (0+10+39+42+49)/5 = 28ms

Prof. MEGHASHRI E M, CSE, SVIT Page 15


Module 2 Chap-2: Process Scheduling

average turnaround time: (10+39+42+49+61)/5 = 40.2ms

Examples on SJF Scheduling (Non Preemptive):

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 7 0 0 0 7 7
2 4 2 8 6 12 10
3 1 4 7 3 8 4
4 4 5 12 7 16 11

Gantt chart:

Average waiting time: (0+6+3+7)/4 = 4ms

Average turnaround time: (7+4+10+11)/4 = 8ms

Example :

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 10 0 10 10 20 20
2 29 0 32 32 61 61
3 3 0 0 0 3 3
4 7 0 3 3 10 10
5 12 0 20 20 32 32

Gantt chart:

Average waiting time: (10+32+0+3+20)/5 = 13ms

Average turnaround time: (10+39+42+49+61)/5 = 25.2ms


Prof. MEGHASHRI E M, CSE, SVIT Page 16
Module 2 Chap-2: Process Scheduling

Examples on SJF Scheduling (Preemptive):

• example 1:

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 8 0 0 9 17 17
2 4 1 1 0 5 4
3 9 2 17 15 26 24
4 5 3 5 2 10 7

Gantt chart:

average waiting time: (9+0+15+2)/4 = 6.5ms

average turnaround time: (17+4+24+7)/4 = 13ms

Example 2:

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 7 0 0 9 16 16
2 4 2 2 1 7 5
3 1 4 4 0 5 1
4 4 5 7 2 11 6

Gantt chart:

average waiting time: (9+1+0+2)/4 = 3ms

average turnaround time: (16+5+1+6)/4 = 7ms

Prof. MEGHASHRI E M, CSE, SVIT Page 17


Module 2 Chap-2: Process Scheduling

Problems on Preemptive Priority Scheduling:

Processes Arrival Time Burst Time Priority


P1 0 5 3
P2 2 6 1
P3 3 3 2
Gantt chart:

P1 P2 P3 P1

0 2 8 11 14

Waiting Completion Turn Around


Process Burst Time Arrival
Time Time Time
1 5 0 9 14 14
2 6 2 0 8 6
3 3 3 5 11 8

P1 Waiting time: (11-2)=9ms, P2 waiting time: (2-2)=0ms, P3 waiting time: (8-3)=5ms

Average waiting time= (9+0+5)/3=14/3= 4.66ms

Average Turnaround time= (14-0)+ (8-2)+ (11-3)/3= (14+6+8)/3= 28/3=9.33ms

Problem non Preemptive Priority Scheduling:

Consider 5 processes which enters ready queue at 0.

Process Burst Time Priority Arrival


1 10 3 0
2 1 1 0
3 2 4 0
4 1 5 0
5 5 2 0

Solution:

Waiting Completion Turn Around


Process Burst Time Priority Arrival Start
Time Time Time

Prof. MEGHASHRI E M, CSE, SVIT Page 18


Module 2 Chap-2: Process Scheduling

1 10 3 0 6 6 16 16
2 1 1 0 0 0 1 1
3 2 4 0 16 16 18 18
4 1 5 0 18 18 19 19
5 5 2 0 1 1 6 6

Gantt chart:

average waiting time: (6+0+16+18+1)/5 = 8.2ms

average turnaround time: (1+6+16+18+19)/5 = 12ms

Problems on Round Robin Scheduling:

Consider 5 processes enters ready queue at 0. Assume Quantum=10ms

Process Burst Time Arrival


1 10 0
2 29 0
3 3 0
4 7 0
5 12 0

Solution:

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 10 0 0 0 10 10
2 29 0 10 32 61 61
3 3 0 20 20 23 23
4 7 0 23 23 30 30

Prof. MEGHASHRI E M, CSE, SVIT Page 19


Module 2 Chap-2: Process Scheduling

5 12 0 30 40 52 52

Gantt chart:

Average waiting time: (0+32+20+23+40)/5 = 23ms

Average turnaround time: (10+39+42+49+61)/5 = 35.2ms

Example:

Consider 4 processes enters ready queue at 0. Assume Quantum=20ms

Waiting Completion Turn Around


Process Burst Time Arrival Start
Time Time Time
1 53 0 0 81 134 134
2 17 0 20 20 37 37
3 68 0 37 94 162 162
4 24 0 57 97 121 121

Gantt chart:

waiting times:

p1: (77-20) + (121-97) = 81

p2: (20-0) = 20

p3: (37-0) + (97-57) + (134-117) = 94

p4: (57-0) + (117-77) = 97

Prof. MEGHASHRI E M, CSE, SVIT Page 20


Module 2 Chap-2: Process Scheduling

Average waiting time: (81+20+94+97)/4 = 73ms

Average turnaround time: (134+37+162+121)/4= 113.5ms

Prof. MEGHASHRI E M, CSE, SVIT Page 21

You might also like