You are on page 1of 4

Republic of the Philippines

Region IV-A CALABARZON


Laguna State Polytechnic University
Santa Cruz, Campus
Province of Laguna

COLLEGE OF COMPUTER STUDIES


ITEL 202 – PLATFORM TECHNOLOGIES

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
ANSWER:
P1 P2 P3 P4 P5 P6
0 10 18 30 34 49 57
(2) Non-preemptive SJF
ANSWER:
P4 P2 P6 P1 P3 P5
0 4 12 20 30 42 57

(3) Preemptive SJF


ANSWER:
P1 P2 P1 P1 P4 P6 P5 P4 P3 P6 P1 P3 P5
0 1 3 3 4 5 6 6 10 17 24 32 43 57

(4) Non-preemptive priority


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

(5) Preemptive priority


ANSWER:
P4 P5 P2 P1 P6 p3
0 4 7 8 14 29 34 40 48 59

(6) Round Robin (TQ = 6)


ANSWER:
P P P P P P P P P P P P
1 2 3 4 5 6 1 2 3 5 6 5 56
0 6 12 18 22 28 34 38 40 46 52 54
Republic of the Philippines
Region IV-A CALABARZON
Laguna State Polytechnic University
Santa Cruz, Campus
Province of Laguna

COLLEGE OF COMPUTER STUDIES


ITEL 202 – PLATFORM TECHNOLOGIES
b) Calculate the average waiting time when using each of the above scheduling
algorithms.
ANSWERS
1. FCFS
Waiting Time
P1 = 0
P2 = 10 = (0+10+18+30+34+49) /6
P3 = 18 = 141 /6
P4 = 30 = 23.5
P5 = 34
P6 = 49

2. NON-PREEMPTIVE SJR
Waiting Time
P4 = 0
P2 = 4 = (0+4+12+20+30+46) /6
P6 = 12 = 108 /6
P1 = 20 = 18
P3 = 30
P5 = 42

3. PREEMPTIVE SJF
Waiting Time
P1 = 0 10 9 8
P2 = 4 8 7 = (8+7+11+3+14+7) /6
P3 = 7 12 11 = 50 /6
P4 = 8 4 3 = 8.3
P5 = 12 15 14
P6 = 14 8 7

4. NON-PREEMPTIVE PRIORITY
Waiting Time
WT = TT – CPU BURST
P1 = 10 – 10 = 0
P2 = 18 – 8 = 10 AWT = (0+10+38+2+10+23) /6
P3 = 50 – 12 = 38 = 13.8
P4 = 6 – 4 = 2
P5 = 25 – 15 = 10
P6 = 31 – 8 = 23

5. PREEMPTIVE PRIORITY
Waiting Time
WT = TT – CPU BURST
P1 = 40 – 10 = 30
P2 = 30 – 8 = 22 AWT = (30+22+40+2+2+26) /6
P3 = 52 – 12 = 40 = 122/6
P4 = 6 – 4 = 2 = 20.3
P5 = 17 – 15 = 2
P6 = 34 – 8 = 26
Republic of the Philippines
Region IV-A CALABARZON
Laguna State Polytechnic University
Santa Cruz, Campus
Province of Laguna

COLLEGE OF COMPUTER STUDIES


ITEL 202 – PLATFORM TECHNOLOGIES
6. ROUND ROBIN (TQ = 60)
Waiting Time
P1 = 28
P2 = 28 = (28+28+27+10 = 29+52) /6
P3 = 27 = 154 /6
P4 = 10 = 25.6
P5 = 29
P6 = 52

c) Calculate the average turnaround time when using each of the above scheduling
algorithms.
ANSWERS:
1. FCFS
Turn Around Time
P1 = 10
P2 = 18 ATAT = (10+18+30+34+49+57) /6
P3 = 30 = 198 /6
P4 = 34 = 33
P5 = 49
P6 = 57

2. NON-PREEMPTIVE SJF
Turn Around Time
P4 = 4
P2 = 12 ATAT = (4+12+20+30+42+57) /6
P6 = 20 = 165 /6
P1 = 30 = 27.5
P3 = 42
P5 = 57

3. PREEMPTIVE SJF
Turn Around Time
P1 = 0 10 9 8
P2 = 4 8 7 = (8+7+11+3+14+7) /6
P3 = 7 12 11 = 50 /6
P4 = 8 4 3 = 8.3
P5 = 12 15 14
P6 = 14 8 7

4. NON-PREEMPTIVE SJF
Turn Around Time
P1 = 10 – 0 = 10
P2 = 22 – 4 = 18 ATAT = (10+18+50+6+25+31) /6
P3 = 57 – 7 = 50 = 140 /6
P4 = 14 – 8 = 6 = 23.3
P5 = 37 – 12 = 25
P6 = 45 – 14 = 31
Republic of the Philippines
Region IV-A CALABARZON
Laguna State Polytechnic University
Santa Cruz, Campus
Province of Laguna

COLLEGE OF COMPUTER STUDIES


ITEL 202 – PLATFORM TECHNOLOGIES
5. PREEMPTIVE PRIORITY
Turn Around Time
TT – TINE FINISHED – ARRIVAL LINE
P1 = 40 – 0 = 40
P2 = 34 – 4 = 30 ATAT = (40+30+52+6+17+34)/6
P3 = 59 – 7 = 52 = 176/6
P4 = 14 - 8 = 6 = 29.8
P5 = 29 – 12 = 17
P6 = 48 - 14 = 34

6. ROUND ROBIN (TQ = 6)


Turn Around Time
P1 = 38
P2 = 36 ATAT = (38+36+39+14+44+40)/6
P3 = 39 = 211/6
P4 = 14 = 35.1
P5 = 44
P6 = 40

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

ANSWER
FCFS (first-come, first-served) scheduling is the simplest scheduling method, however it can cause short cycles to
stick around for unusually lengthy periods of time. Starvation may have negative consequences for both need and
SJF scheduling.

You might also like