Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

TSN2101/TOS2111

– Tutorial 4 (Process Scheduling) - Solutions



1. Why is it important for the scheduler to distinguish I/O-bound programs from CPU-bound
programs?

Solution:
I/O-bound programs have the property of performing only a small amount of computation before
performing I/O. Such programs typically do not use up their entire CPU quantum. CPU-bound
programs, on the other hand, use their entire quantum without performing any blocking I/O
operations. Consequently, one could make better use of the computer’s resources by giving
higher priority to I/O-bound programs and allow them to execute ahead of the CPU-bound
programs.

2. What is the difference between preemptive and non-preemptive scheduling?

Solution:
Preemptive scheduling allows a process to be interrupted in the midst of its execution, taking the
CPU away and allocating it to another process. Non-preemptive scheduling ensures that a process
relinquishes control of the CPU only when it finishes with its current CPU burst.

3. Explain the difference in the degree to which the following scheduling algorithms discriminate in
favor of short processes.

a) FCFS
b) RR

Solution:
a) FCFS – discriminates against short jobs since any short jobs arriving after long jobs will have a
longer waiting time.
b) RR – treats all jobs equally (giving them equal bursts of CPU time) so short jobs will be able to
leave the system faster since they will finish first.


4. Consider the following set of processes, with the length of the CPU-burst time given in
milliseconds:

Process Burst-time Arrival time
P1 10 0
P2 2 1
P3 3 2
P4 1 3
P5 5 4

a) Draw the Gantt charts illustrating the execution of these processes using FCFS,
Non-Preemptive SJF, Pre-emptive SJF (Shortest Remaining Time First) and RR (quantum=2)
scheduling.
b) What is the turnaround time of each process and also average turnaround time for each of
the scheduling algorithms?
c) What is the waiting time of each process and also average waiting time for each of the
scheduling algorithms?
d) Which of the above scheduling algorithm results in the minimal average waiting time (over
all processes)?



1
Solution:

a) Gantt Charts:

FCFS
1 2 3 4 5
0 10 12 15 16 21

RR
1 2 3 1 4 5 3 1 5 1 5 1
0 2 4 6 8 9 11 12 14 16 18 19 21

Non-Preemptive SJF
1 4 2 3 5
0 10 11 13 16 21

Pre-emptive SJF (Shortest Remaining Time First):

1 2 4 3 5 1
0 1 3 4 7 12 21


b. Turnaround time = (Finish Time – Arrival Time)

FCFS RR Non-preemptive SJF Preemptive SJF
P1 10 21 10 21
P2 11 3 12 2
P3 13 10 14 5
P4 13 6 8 1
P5 17 15 17 8

Average Turnaround time :
FCFS: 64/5 = 12.8ms
RR: 55/5 = 11ms
Non-preemptive SJF: 61/5 = 12.2ms
Preemptive SJF: 37/5 = 7.4ms

c. Waiting time=(Turnaround time – CPU burst time)

FCFS RR Non-preemptive SJF Preemptive SJF
P1 0 11 0 11
P2 9 1 10 0
P3 10 7 11 2
P4 12 5 7 0
P5 12 10 12 3

Average waiting time :
FCFS: 43/5 = 8.6ms
RR: 34/5 = 6.8ms
Non-preemptive SJF: 40/5 = 8ms
Preemptive SJF: 16/5 =3.2ms

d. Preemptive SJF results in minimal average waiting time.

2
5. Consider the following processes with the length of a CPU burst time given in milliseconds.
Assume that lower numbers represent higher priority.

Process Arrival Time Priority Burst Time
P0 0 2 8
P5 0 1 6
P1 4 5 15
P4 9 4 13
P2 7 3 9
P3 13 1 5

a) Draw the Gantt Charts illustrating the execution of these processes using the following
scheduling algorithms.
i. Non-preemptive SJF
ii. Pre-emptive SJF
iii. Non-preemptive priority scheduling
iv. Preemptive priority scheduling
v. Round Robin (quantum=3) scheduling
b) Calculate the average turnaround time and waiting time for all the above scheduling
algorithms.

Solution:

a) Gantt Charts:

(i) Non-preemptive SJF
P5 P0 P3 P2 P4 P1
0 6 14 19 28 41 56

(ii) Preemptive SJF
P5 P0 P3 P2 P4 P1
0 6 14 19 28 41 56

(iii) Non-preemptive priority scheduling

P5 P0 P3 P2 P4 P1
0 6 14 19 28 41 56


(iv) Preemptive priority scheduling
P5 P0 P3 P0 P2 P4 P1
0 6 13 18 19 28 41 56

(v) Round Robin (quantum=3) scheduling
P5 P0 P5 P1 P0 P2 P4 P1 P3 P0
0 3 6 9 12 15 18 21 24 27 29

P2 P4 P1 P3 P2 P4 P1 P4 P1 P4
29 32 35 38 40 43 46 49 52 55 56





3



d. Turnaround time = (Finish Time – Arrival Time)


A Non-preemptive Preemptive Non-preemptive Preemptive RR
v SJF SJF Priority Priority
e
P0 14 14 14 19 29
r
P1 56 56 56 56 55
a
g P2 28 28 28 28 43
e P3 19 19 19 18 40
P4 41 41 41 41 56
P5 6 6 6 6 9

Average Turnaround time:
Non-preemptive SJF: 131/6 = 21.83ms
Preemptive SJF: 131/6 = 21.83ms
Non-preemptive Priority: 131/6 = 21.83ms
Preemptive Priority: 135/6 = 22.5ms
RR: 199/6=33.17ms

Waiting time=(Turnaround time – CPU burst time)

A Non-preemptive Preemptive Non-preemptive Preemptive RR
v SJF SJF Priority Priority
e P0 6 6 6 11 21
r P1 37 37 37 37 36
a
P2 12 12 12 12 27
g
P3 1 1 1 0 22
e
P4 19 19 19 19 34

P5 0 0 0 0 3
w

Average Waiting time:
Non-preemptive SJF: 75/6 = 12.5ms
Preemptive SJF: 75/6 = 12.5ms
Non-preemptive Priority: 75/6 = 12.5ms
Preemptive Priority: 79/6 = 13.17ms
RR: 143/6=23.83ms


References:
• Abraham Silberschatz, Peter Baer Galvin, Greg Gagne, “Operating System Concepts”, 9/E, John
Wiley & Sons, 2013.
— William Stallings, "Operating Systems: Internals and Design Principles", 8/E, Pearson, 2015.

You might also like