You are on page 1of 4

Republic of the Philippines

Laguna State Polytechnic University


Province of Laguna

Activity 3: CPU Scheduling

1. Consider the following set of processes, with the arrival times and the length of the
CPU‐burst times given in milliseconds, and the priorities given so that smaller priority
number means a higher priority.

Process Arrival time Burst time(ns) Priority


P1 0 10 3
P2 4 8 2
P3 7 12 4
P4 8 4 1
P5 12 15 2
P6 14 8 3

a) Draw Gantt charts illustrating the execution of these processes using the following
scheduling algorithm:
(1) FCFS
(2) non-preemptive SJF
(3) preemptive SJF
(4) non-preemptive priority
(5) preemptive priority
(6) Round Robin (TQ = 6).

b) Calculate the average waiting time when using each of the above scheduling
algorithms.
c) Calculate the average turnaround time when using each of the above scheduling
algorithms.

Ans:
(1) FCFS
P1 P2 P3 P4 P5 P6
0 10 18 30 34 49 57

Waiting Time: Turn Around time:


P1 = 10 – 10 = 0 P1 = 10 – 0 = 10
P2 = 14 – 8 = 6 P2 = 18 – 4 = 14
P3 = 23 – 12 = 11 P3 = 30 – 7 = 23
P4 = 26 – 4 = 22 P4 = 34 – 8 = 26
P5 = 37 – 15 = 22 P5 = 49 – 12 = 37
P6 = 45 – 8 = 37 P6 = 57 – 14 = 43

Average Waiting time: Average TAT:


AWT = (0+6+11+22+22+37)/6 ATAT = (10+14+23+26+37+43)/6
= (98)/6 = 155/6
AWT = 16.6 ms ATAT = 25.83ms
Republic of the Philippines
Laguna State Polytechnic University
Province of Laguna

(2) Non- preemptive SJF

P1 P4 P6 P2 P3 P5
0 10 14 22 30 45 57

Waiting Time: Turn Around time:


P1 = 10 – 10 = 0 P1 = 10 – 0 = 10
P2 = 26 – 8 = 18 P2 = 30 – 4 = 26
P3 = 35 – 12 = 23 P3 = 42 – 7 = 35
P4 = 6 – 4 = 2 P4 = 14 – 8 = 6
P5 = 45 – 15 = 30 P5 = 57 – 12 = 45
P6 = 8 – 8 = 0 P6 = 22 – 14 = 8

Average Waiting time: Average TAT:


AWT = (0+18+23+2+30+0)/6 ATAT = (10+26+35+6+45+8)/6
= (73)/6 = 130/6
AWT = 12.16ms ATAT = 21.6ms

(3) preemptive SJF


P P4 P2 P6 P1 P3 P5
1
0 1 5 13 21 30 42 57

Waiting Time: Turn Around time:


P1 = 0 + (21 – 1) = 20 P1 = 10 – 0 = 10
P2 = 5 – 4 = 1 P2 = 22 – 4 = 18
P3 = 30 – 7 = 23 P3 = 57 – 7 = 50
P4 = 1 – 8 = -7 P4 = 14 – 8 = 6
P5 = 42 – 12 = 30 P5 = 37 – 12 = 25
P6 = 13 – 14 = -1 P6 = 45 – 14 = 31

Average Waiting time: Average TAT:


AWT = (20+1+23-7+30-1)/6 ATAT = (10+18+50+6+25+31)/6
= 66/6 = 140/6
AWT = 11ms ATAT = 23.3ms

(4) non-preemptive priority


P1 P4 P2 P5 P6 P3
0 10 14 22 37 45 57

Waiting Time: Turn Around time:


P1 = 10 – 10 = 0 P1 = 10 – 0 = 10
P2 = 14 – 4 = 10 P2 = 22 – 4 = 18
P3 = 45 – 7 = 38 P3 = 57 – 7 = 50
P4 = 10 – 8 = 2 P4 = 14 – 8 = 6
P5 = 22 – 12 = 10 P5 = 37 – 12 = 25
P6 = 37 – 14 = 23 P6 = 45 – 14 = 31

Average Waiting time: Average TAT:


AWT = (0+10+38+2+10+23)/6 ATAT = (10+18+50+6+25+31)/6
= 83/6 = 140/6
AWT = 13.83ms ATAT = 23.3ms
Republic of the Philippines
Laguna State Polytechnic University
Province of Laguna

(5) preemptive priority


P1 P2 P4 P2 P5 P1 P6 P3
0 4 8 12 16 31 37 45 57

Waiting Time: Turn Around time:


P1 = 0 + (31 – 4) = 27 P1 = 37 – 0 = 37
P2 = (4 – 4) + (12 – 8) = 4 P2 = 16 – 4 = 12
P3 = 45 – 7 = 38 P3 = 57 – 7 = 50
P4 = 18 – 8 = 0 P4 = 12 – 8 = 4
P5 = 16 – 12 = 4 P5 = 31 – 12 = 19
P6 = 37 – 14 = 23 P6 = 45 – 14 = 31

Average Waiting time: Average TAT:


AWT = (27+4+38+0+4+23)/6 ATAT = (37+12+50+4+19+31)/6
= (96)/6 = 153/6
AWT = 16ms ATAT = 25.5ms

(6) Round Robin (TQ = 6).


P1 P2 P3 P4 P5 P6 P1 P2 P3 P5 P P5
6
0 6 12 18 22 28 34 38 40 46 52 54 57

Waiting Time: Turn Around time:


P1 = 34 – 6 = 28 P1 = 38
P2 = 38 – 6 = 32 P2 = 40
P3 = 40 – 6 = 34 P3 = 46
P4 = 18 P4 = 22
P5 = 54 – 12 = 42 P5 = 57
P6 = 52 – 6 = 46 P6 = 54

Average Waiting time: Average TAT:


AWT = (28+32+34+18+42+46)/6 ATAT = (38+40+46+22+57+54)/6
= 200/6 = 257/6
AWT = 33.3ms ATAT = 42.8ms
2. Which of the following scheduling algorithms could result in starvation, and why?
a. First‐come, first‐served
b. Shortest job first
c. Round robin
d. Priority

D. Priority, because Priority scheduling allocates system resources to the activities that
require them the most, while starving the programs that aren't high on the priority list.
Republic of the Philippines
Laguna State Polytechnic University
Province of Laguna

Turnaround time = burst time + arrival time

You might also like