0% found this document useful (0 votes)
5 views23 pages

Scheduling Algorithms

The document discusses various CPU scheduling algorithms, including First Come First Serve (FCFS), Shortest Job First (SJF), Priority Scheduling, and Round Robin Scheduling. Each algorithm is described in terms of its implementation, advantages, and disadvantages, along with examples illustrating their operation and calculations for average waiting and turnaround times. The document also compares FCFS and Round Robin scheduling, highlighting their differences in preemption, overhead, response time, and suitability for time-sharing systems.

Uploaded by

agdanishr
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)
5 views23 pages

Scheduling Algorithms

The document discusses various CPU scheduling algorithms, including First Come First Serve (FCFS), Shortest Job First (SJF), Priority Scheduling, and Round Robin Scheduling. Each algorithm is described in terms of its implementation, advantages, and disadvantages, along with examples illustrating their operation and calculations for average waiting and turnaround times. The document also compares FCFS and Round Robin scheduling, highlighting their differences in preemption, overhead, response time, and suitability for time-sharing systems.

Uploaded by

agdanishr
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
You are on page 1/ 23

AU : Dec.

-17, May-17, 18, 19, 22


2.6 Scheduling Algorithms
CPUscheduling algorithms are as follows :
Shortest job first scheduling
1. First In First Out (FIFO) scheduling 2.
3. Priority scheduling 4. Round robin scheduling

knowledge
TECHNICAL PUBLICA TIONs an up-thrust for
Introduction to Operating Systems 2-26 Process Management

2.6.1 First Come First Serve Scheduling


This method of scheduling means that the first process to request the processor
gets it until it finished execution. With this algorithm, processes are assigned the
CPUin the order they request it.
Normally there is a single queue of ready processes. When the first process enters
the system from the outside, it is started immediately and allowed to run as
as it wants it. At the same time, other process enters into the system; they long
are put
onto the end of the queue.
New process enters the tail of the queue and the schedule selects the process
from
the head of the queue.

When new process enters into the system, its process control block is
linked to the
end of the ready queue and it is removed from the front of
the queue.
When a process waits or blocks, it is removed
from the queue and it queues up
again inFCFS queue when it gets ready.
FCFS is non-preemptive CPU scheduling algorithm. It
Out method (FIFO). is also called First In First
FCFS is simple to implement because it
for most of the batch
uses a FIFO queue. This algorithm is
operating systems. fine
FCFS is not useful in scheduling
interactive processes because it cannot
short response time.This algorithm guarantee
short ones. performs much better for long processes than
Turnaround time is unpredictable with the FCFS
of the FCFS is often quite algorithm. Average waiting time
long.
Real life analogy is buying
tickets.
Example 2.6.1 Consider the following
set of process that
arrives at time 0, with the length of the Process Burst time
CPU burst
given in milliseconds
PË 14
Calculate the average waiting time.
P2 2

P3 4
Solution:

Gantt chart :

P1
P2 P3
14 16
20

TECHNICAL PUBLICATIONS® - an
up-thrust for knowledge
2- 27 Process Management
Introduction to Operating Systems

CPUburst uses the


Such a diagram is called "Gantt charts", showing when each
from a different thread.
CPU. Here, each CPUburst comes
Waiting Time :

Process Waiting time

P;
14
P2
16
P3

Sum of P, P, and P, waiting time


Average waiting time
0+14+16
= 10
3
will
arrive ie. P, Pa P, then the results
the processes change their order of
" If below:
different than first one and it is shown
be
Gantt chart :
P4
P2 P3 20
6
0 2

Waiting Time : Waiting time


Process

6
P
P
P3
waiting time
Sum of P, P and Pa
Average waiting time 3

6+0+2
= 2.66
3

waiting
Convey effect bound processes will be
I/0
device utilization, all effect.
To reduce I/O ones. This is called as convey
processor bound
excessively long for
extent of its overall effect on system
monopolizes the system,
the is
" If one process scheduling policy and whether the process
performance depends on the
I/0bound.
processor bound or

TECHNICAL PUBLICA TIONS - an up-thrust for knowledge


Introduction to Operating Systems 2- 28 Process Managemens
Advantages
1. Simple to implement
2. Fair

Disadvantages
1. Waiting time depends on arrival order
2. Convoy effect : short process stuck waiting for long process
3 Also called head of the line blocking
Example 2.6.2 Consider the folloving set of process
Process Burst time
that arrive at time 0, with the length of CPU
burst given in nilliseconds. Calculate the average P 4

waiting time when the processes arrive in the P2 7

following order : P3 3

a. P, P, P3, Py Ps PA 3
Provide the Gantt chart for the Same.
P5 5

Solution :

Gantt chart :

P P2 P3 PA P5
4 1 14 17 22

Such diagram is called Gantt charts, showing when


each process burst uses the CPU:
Waiting time

Process Waiting time


PË 0 -0= 0

P2 4 0 = 4

P3 11 0= 11
PA 14 0 = 14

P's 17 0 = 17

0+4+11+14 +17 46
Average waiting time 5
= 9.2
5

TECHNICAL PUBLICATIONSs -an up-thrust for knowledge


Introduction to Operating Systems 2- 29 Process Management

Turnaround time: Turnaround time = Waiting time + Burst time

Process Turnaround time

0 + 4 = 4
P
4 +7 = 11
Pzws
11 +3 = 14
P3
14 + 3 = 17
P4
17 + 5 = 22
Ps

4+11+14+17+22 68 = 13.60
Average turnaround time 5 5

2.6.2 Shortest Job First Scheduling


known as Shortest Job Next (SJN)
scheduling algorithm is also
Shortest job first on length of their CPUcycle
handles the process based
scheduling algorithm. It algorithm.
waiting time over FIFO
time. It reduces average
CPUscheduling algorithm.
SJF is anon-preermptive because users do not
estimate in advance
interactive system
" It does not work in
run their processes.
the CPUtime required to scheduling.
algorithm is used frequently in long term
SJF scheduling the system for how long it
wants
aCPU, it must inform
When a process request
to use the CPU. into processes with the
least
system allocates
available, the
When CPU become
expected execution time.
algorithn.
follows the FCFS
To break ties, it Remnaining Time Next (SRTN)
called as Shortest
Preemptive version of SJF is process, whereas a
algorithm will preempt the currently exceutig finish its
Preemptive SJF currently running process to
will allow the
non preemptive SJF algorithm
CPUburst.
manner ensuring the next
one will complete
for service in a
SIE selects processes possible.
leave the system as sOon as
and

TECHNICAL PUBLICA TIONs an up-thrust for knowledge


Introduction to Operating Systems 2-30 Process Managemer.
Example 2.6.3 Calculate the average waiting time and average turnaround time. Provide th.
Gantt chart for the same.

Process Burst time


5
P1
P2 2

P3 6

P4 4

Solution :

Gantt chart:

P2 Pa P4 P3
2 11 17

Waiting time :

Process Waiting time


P 6-0 =6

P 0-0 = 0

P3 11 -0 = 11

2-0= 2

6+0+11+2 19
Average waiting time = 4 4
= 4.75

Turnaround time : Turnaround time =Waiting time + Burst time

Process Turnaround time

P; 6 +5 = 11

P2 0 +2 =2

11 + 6 = 17
P3
2 + 4 = 6
PA

11+2+17+6 36
Average turnaround time =
= 9
4 4

TECHNICAL
PUBLICATIONs an up-thrust for knowledge
Introduction to Operating Systems 2-31 Process Management

The SJF scheduling algorithm is optimal only when all of the processes are
available at the same time and the CPUestimates are available.
sJF scheduling algorithm may be preemptive or non-preemptive.
2.6.3 Priority Scheduling
algorithm. It
Priority CPU scheduling algorithm is preemptive and non-preemptive
system. Priority can be
batch
is one of the most common scheduling algorithm in
process.
assigned by a system admin using characteristics of the
first. If the priority
In this scheduling algorithm, CPUselect higher priority process
applied for solving the
scheduling algorithm is
of two process is same then FCFS
problem.
quickly its request for a CPU will
be
process determines how
The priority of a
granted if other processes make competing requests.
scheduling.
process is assigned a priority number for the purpose of CPU
Each
non negative integer number.
The priority number is normally a
priority scheduling algorithm will simply put the new process at
Non preemptive
the head of the ready queue.
algorithm will preempt the CPU if the priority of
Preemptive priority scheduling priority of the currently running
process is higher than the
the newly arrived
process.
arrive at time 0, with the length
of
following set of process that
Example 2.6.4 Consider the average wvaiting time and average
milliseconds. Calculate the
CPU burst given in slice = 2)
Provide the Gantt chart for the sane. (Time
turnaround time.
Burst time Priority
Process
3
P;
4
2
P
6 1
P3
4
P4

non-preemptive priority scheduling


Solution: For
Gantt chart

P3 P4 P P2
6 10 15 17

TECHNICAL PUBLICATIONS -an up-thrust for knowledge


Introduction to Operating Systerms 2- 32 Process Managemen

Waiting time :
Process Waiting time
10 --0 = 10
P,
15 - 0 = 15
P2
P3 0 -0 = 0

P4 6-0 =6

10+15+0+6 31
Average waiting time 4 4
= 7.75

Turnaround time : Turnaround time = Waiting time + Burst time


Process Turnaround time

P 10 +5 = 15

P2 15 + 2 = 17

P, 0 + 6 =6

P4 6 + 4 = 10

Average turnaround timne = 15+17+6+10 =


48
= 12
4 4
Problem with Priority Scheduling
Waiting time is more for lower priority process even if there required CPUburst
time is less. Priority scheduling algorithm faces the starvation problem.
Starvation
problem can be solved by using aging techniques.
In aging, the priority of the process will increase which is waiting for long
time in
the ready queue.
2.6.4 Round Robin Scheduling
Round robin is a preemptive scheduling algorithm. It is used in interactive
system.
Here process are given a limited amount of time of processor time called a
time
slice or time quantum. If a process does not complete before its
quantum expires
the system preempts it and gives the processor to the next waiting process. The
system then places the preempted process at the back of the ready queue.
Processes are placed in the ready queue using a FIFO scheme. With the RK
algorithm, the principle design issue is the length of the time quantum to be used.
For short time slice, processes will move through the system relatively quickly. I
increases the processing overheads.
TECHNICAL PUBLICATIONS an up-thrust for knowledge
Process Management
Introduction to Operating Systems 2- 33

Example 2.6.5 Consider the following set of process that arrive at tine 0, with the length
of
CPU burst given in milliseconds. Calculate the average waiting time and average
turnaround time. Provide the Gantt chart for the same. (Time slice = 2)
Process Burst time

5
P1
P2
6
P3
4
P4
Solution :
Gantt chart :

PA P P3
P P3 PA P P3
P1 17
12 14 15
10
0 2

Waiting time :
Waiting time
Process
0-0 + 8- 2+ 14
- 10 = 10

2-0 =2
P2
+ 15 - 12 = 11
4 -0 + 10 - 6
Pz
6-0 + 12 - 8 = 10
P4
10+2+11+10 33 = 8.25
time = 4
Average waiting 4
time
time + Burst
Turnaround time = Waiting
Turnaround time :
Turnaround time
Process

10 + 5 = 15
P
2 +2 = 4
P
11 + 6 = 17
P'3
10 + 4 = 14
P4

15+4 +17+14 50
time = = 12.5
Average turnaround 4 4

TECHNICAL PUBLICATIONS an up-thrust for knowledge


Introduction to Operating Systems 2-34 Process Management

2.6.5 Comparison between FCFS and RR


Sr. No. FCFS Round robin

1 FCFS decision made is non-preemptive. RR decision made is preemptive.


It has minimum overhead. It has low overhead.

3 Response time may be high. Provides good response time for short
processes.

4 is troublesome for time sharing It is mainly designed for time sharing


Systenm. system.
5. It is similar like FCFS but uses time
The workload is simply processed in the
order of arrival. quantum.

6 No starvation in FCFS. No starvation in RR.

2.6.6 Comparison of CPU Scheduling Algorithm


Algorithm Policy type Used in Advantages Disadvantages
FCFS Non-preemptive Batch 1. Easy to 1. Unpredictable turn
implement. around time.
2. Minimum 2. Average waiting is
overhead. more.
RR Preemptive Interactive 1. Provides fair 1. Requires selection of
CPU good time slice.
allocation.
2. Provides
reasonable
response times
to interactive
users.

Priority Non-preemptive Batch 1. Ensures fast 1. Indefinite


completion of postponement of some
important jobs. jobs.
2. Faces starvation
problem.
SJF Non-preemptive Batch 1. Minimizes 1. Indefinite
average postponement
waiting time. of some jobs.
2. SJF algorithm 2. Cannot be
is optimal. implemented
at the level of short
term scheduling.
3. Difficulty is knowing
the length of the next
CPUrequest.

TECHNICAL PUBLICA TIONS an up-thrust for knowledge


Process Management
Introduction to Operating Systems 2-35

Preemptive or Batch/Interactive 1. Flexible. 1.Overhead incurred by


Multilevel
Non-preemptive 2.Gives fair monitoring of queues.
queues
treatment to
CPUbound
jobs.

Consider the following process, with


the CPU burst time given in
Example 2.6.6
milliseconds.
Process Burst time Priority
10 3
P
1
P2
3
2
P3
4
P4
5

order at time 0.
Processes are arrived in P, P, Pa Pa, P, non-preemptive
execution using FIFO, SJF,
to show
(i) Drawfour Gantt charts (Quantum = 1) scheduling.
Robin scheduling algorith1m.
priority and Round time for each
time and turnaround Marks 15
Also calculate waiting AU : May-18,
(ii)

Solution :
chart :
FIFO : Gantt
P4 P5
P2 P3
19
P1 13 14
11
10
Turnaroud time for FIFO
FIFO
Waiting time for
Process 0+ 10 = 10

10 + 1 = 11
P1 10
11 + 2 = 13
P2 11
P3 13 + 1 = 14
13
14 +.5 = 19
14

Ps
Sum of all processes waiting time
Average waiting time 5
0 + 10 + 11 + 13 + 14
= 9.6
5

TECHNICAL PUBLICATIONS® - an up-thrust for knowledge


Introduction to Operating Systems 2-36 Process Management

Average turnaround time =


Sum of all processes turnaround time
5
10 + 11 + 13 + 14 + 19
= 13.4
5

2) SJF

P2 PA P3 Ps P,
0 1 2 9 19

Process Waiting time for SJF Turnaroud time for SJF


P 9 + 10= 19
P 0+1 1
P3 2 2+2 = 4
P4 1 1+1 = 2
P; 4
4+5 =9

Average waiting time Sum of all processes waiting time


5
9 + 0 + 2 +1 + 4
= 3.2

Average turnaround time Sum of all processes turnaround


time
5
19 + 1 + 4 + 2 + 9
=7

3) Non-Preemptive Priority
Gantt chart : (1 is highest
priority and 4 is lowest priority)
P2 P5 P4
1
P3 P4
16 18 19
Process
Waiting time for
Non-Preemptive Priority Turnaroud time for
P 6
Non-Preemptive Priority
6 + 10 = 16
P
0 + 1 = 1
P3 16
16 + 2 = 18
PA 18
18 + 1 = 19
P5
1+5 = 6
TECHNICAL PUBLICATIONS - an up-thrust for knowledge
Introduction to Operating Systems 2-37 Process Management

Sum of all processes waiting time


Average waiting time = 5

6+0 + 16 + 18 + 1
= 8.2
5

Sum of all processes turnaround time


Average turnaround time 5

16 + 1 + 18 + 19 + 6 = 13.2
5

4) Round Robin (Quantum = 1)

P, P1 P4 P4
P5 P1 P5 P. Ps
Pa P5 P1 P3 Ps P
P. P P3 19
15 16 17 18
11 12 13 14
7 10
3 4 5 6
1 2

Turnaroud time for Round Robin


Robin
ProcesS Waiting time for Round
9 + 10 = 19
9
P; 1+1= 2
1
P2 3 + 2 = 5
3
3+ 1= 4
3
P'4 9+5= 14

P'5
Sum of allprocesses waiting
time
Average waiting
time =
9 + 1+ 3 + 3 + 9
5
turnaround time
Sum of all processes
turnaround time =
Average

19 + 2 +5 + 4 + 14 = 8.8
5

TECHNICAL PUBLICATIONs an up-thrust for knowledge


Introduct1on to Operating Systems 2-38 Process Managemen
Example 2.6.7 Consider the following set of processes with the length of CPU - burst time
given in milliseconds.

Process Burst time Priority Arrival time

P 10 3

P 1 1 1

P 2 3 2

P 4 1

Draw the Gantt chart for execution of these processes


using FCFS, SJF, SRTS, pre-emptie
and non-pre-emptive priority, round robin with time slice of 2
ms. Find the average waiting and
turnaround time using each of the methods.
AU : May-19, Marks 10
Solution :

i) FCFS (Gantt chart)

P, P P4
0
P3 Ps
10 11 12 14 19
ii) SJF

P1 P2 P4
0 Pa P5
10 11 12 14 19
ii) SRTF (Gantt chart)

P P2 PA P3
1 2
P5 P1
3 5
10
19
iv) Preemptive priority

P, P2 Ps P1
0 1 2 7 P3 P4
16 18 19
v) Non-preemptive priority

P, P2 Ps P3 P4
10 11
16 18 19

TECHNICAL PUBLICATIONS - an up-thrust for


knowledge
Process Management
Introduction to Operating Systems 2-39

vi) Round robin (time slice = 2)


Ps P P4
PP2 PA Ps P5 P Ps P1
17 19
2 3 4 6 8 10 12 14 15

Waiting time :
Round Robin
FCFS SJF SRFT Preemptive Non-preemptiv
Process
Priority e Priority
0-0+8-2+12-1
0-0+7 0-0 =0
0-0 = 0 0-0 = 0 0-0 +10 - 1 0 + 15- 14 = 9
= 9 -1=6
2-1 = 1
1-1 = 0 10 - 1=9
10-1 = 9 10 -1 =9 1-1= 0
P 4-2 = 2
16-2 14 16 - 2 = 14
12 -2 = 10 12-2 =10 3 -2 = 1
P 3-1= 2
18-1 17 18 - 1 = 17
2 - 1 = 1
P 11 -1= 10 11-1= 10
11 -2 =9 6-2+10 8
5-2 = 3 2-2 = 0 = 8
14-2 = 12 14-2 = 12 + 14-12

Turnaround time
Round
Preemptive Non-preemptive
SRTF Robin
FCFS SJF Priority Priority
10 + 0 = 10 10 +9 = 19
10 +9 = 19 10+6 = 16
10 +0 10
10 + 0= 10 1+1= 2
1 +9 = 10
1 +0 =1 1+0 =1
1+9 = 10 1+9 = 10
2 + 14 =16 2+2 = 4
2 +1= 3 2+ 14 = 16
2+ 10 = 12 2+ 10 = 12
1+ 17 = 18 1+2= 3
1+1= 2 1+17 =18
1+ 10 = 11 1+ 10=11
P 5+9 = 14 5+8 = 13
5 +3 = 8 5+0 =5
5+ 12 = 17 5+ 12 = 17

turnaround time
Average waiting time and
Average Turnaround time
Averege Waiting time

(10+ 10 +12 + 11 + 17) /5 12


FCFS (0 +9 + 10 + 10 + 12) /5 =8.2
5 = 8.2 (10+ 10+ 12 + 1l + 17) /5= 12
(0 +9 + 10+ 10+ 12)/
SJF
(9+0+ 1+1+3)/5 =2.8 (19 + 1 +3+2 +8) /5 =7
SRTF
(16 +1 + 16 + 18 +5) /5= 11.2
(6+0+ 14 + 17+ 0) /5=7.4
Preemptive priority
/5= 13.6
(0 +9+ 14 +17+9) /5=9.8 (10 + 10+ 16 + 18 + 14)
Non-Preemptive priority
(9 +1+2+2+8) /5=4.4 (19 +2 + 4 +3 + 13) /5 = 8.2
Round Robin

TECHNICAL PUBLICATIONS - an up-thrust for knowledge


Introduction to Operating Systems 2- 40 Process Management
2.6.7 Shortest Remaining Time Next
Preemptive SJF is called shortest remaining time first. In this algorithm, the
scheduler selects the process with the smallest estimated run time to completion.
" This scheduler gives minimum wait times in theory but in certain
situation due to
preemption overhead, shortest process first might performance better.
An advantageous of this method is that, the short
processes are handled Ver:
quickly. The system requires very little overhead since it only
when a process completes or a new process is
makes a decision
added. When a new process is
admitted the SRTN algorithm only needs to
compare the currently executing
process with the new process, ignoring all other
execute. processes currently waiting o
Consider the four processes with their arrival
and burst time.
Process Burst Time
Arrival time
P1
6
0
P2
2
1
P3
8
P4 2
4
" The 3
execution of the process is shown by the
Gantt chart :
P. P2 P4 P
3
Ps
7
12
20
Now we calculate
waiting time and
turnaround time for all
Process processes.
Waiting Time
P1
(0 - 0) + (7 -1) = 6 Turnaround time
P2 6+6 = 12
1-1= 0
P 2+0 = 2
12 - 2 = 10
P4 8+ 10 =18
3-3 = 0
4 +0 = 4
Average waiting time = 6+0+10+0 16
= 4
4 4
12+2+18+4 36
Average waiting time 4 4
=9

TECHNICAL PUBLICATIONS - an up-thrust for knowledge


2-41 Process Management
Introduction to Operating Systems

Advantages :
1. Very. short processes get very good service.
in most cases
The penalty ratios are small; this algorithm works extremely well
highest throughput of all scheduling
3 This algorithm provably gives the correct.
if the estimates are exactly
algorithms
Scheduling
Queue
2.6.8 Multilevel
not separate scheduling algorithm but it works in conjunction
Multilevel queue is
scheduling algorithms. The processes can be grouped according
with several CPU
to common characteristics.

different
queue is based on the priority based system with
One type of multilevel
level.
queues for each priority Interactive and batch.
types of processes or jobs :
System consists of two longer. Fig. 2.6.1 shows multilevel
and batch jobs are
Interactive jobs are shorter
queue scheduling.

System High priority


procesS
queue

Interactive Medium RR CPU


process
priority queue scheduling
scheduling
FCFS

Batch Low priority Priority


process queue scheduling

Fig. 2.6.1 Multilevel queue scheduling


scheduled before the
" To keep minimum response time for user, interactive jobs are
separate queue: interacthve
JobS. So ready queue is. partitioned into two scheduling
(TOreground) and batch (background). Each queue uses their own
algorithm.
nce the jobs assigns to the queue. it will remain in that queue. Jobs never cnange
the
queue, Here we assume that FCES is applied to one gueue and round robm
method is applied to another queue.
The batch jobs are put in one queue called the background queue while the
interactive jobs are put in a foreground queue. Batch jobs are scheduled by first
Come first
serve method and interactive jobs by round robin method.

TECHNICAL PUBLICATIONS® - an up-thrust for knowledge


Introduction to Operating Systems 2-42 Process Management

Ihe scheduler now has to decide which queue to run. The methods are as
follows :
I. Higher priority queues can be processed until they are empty before the lowex
priority queues are executed.
2. Each queue can be given a certain amount of the CPU. Maybe, the interactive
queue could be assigned 75 % of the CPU, with the batch queue being given
25 %.
" It should also be noted that there can be many other queues. Many systems will
have a system queue. This queue will contain processes that are important to keep
the system running. For this reason these processes normally have the highest
priority.
It should be also need to specify which queue a process will be put to when it
arrives to the system and,/or when it starts a new CPUburst.
Advantages :
1. It can be preemptive or non-preemptive.
2. Short CPUbound processes are executed first.
3. Simple to implement.
Disadvantage :
1 Queues require
monitoring, which is a costly activity.
2.6.9 Multilevel Feedback Queue Scheduling
Multilevel Feedback Queue (MLFQ) allows moving the
processes between the
queues. MLFQ has a number of distinct queues; each assigned a
level. At any different priority
given time, a process that is ready to run is on a
MLFQ uses priorities to decide which process should single queue.
run at a given time. A
process with higher priority is selected for execution.
Consider processes with different CPU burst
much of the CPUit will be moved to a lower
characteristics. If a process uses too
priority queue. This will leave I/0
bound and interactive processes in the higher
priority queue.
Fig. 2.6.2 shows multilevel feedback queue
scheduling. (See Fig. 2.6.2 on next
page.)
MLFQ also uses concept of aging to prevent starvation.
The processes with lower
priority will move towards the higher priority queue in
aging
MLFQ scheduling lies in how the scheduler sets priorities. concept. The key to
Rather than giving a
fixed priority to each process, MLFQ varies the priority of a process
observed behavior.
based on its

TECHNICAL PUBLICA TIONs an up-thrust for knowledge


Process Management
troduction to Operating Systems 243

Queue

Entry CPU) + Exit

Queue

-000--O CPU) Exit

Queue

(CPU} Exit

Queue

CPU) + Exit
OO0--0
scheduling
feedback queue
Fig. 2.6.2 Multilevel
Q0 is the lowest priority queue
Q1 and 02).
Assume we have
three queues (Q0, enters at the highest priority
process
highest priority queue. The reduces the process's
priority
and Q2 is the the scheduler is
single time-slice of 10 ms, for a time slice, the job
(Q2). After a After running at
Q1
the job is on Q1. it remains.
by one, and
thus
in the system (Q0), where
lowered to the lowest priority implementing
MLFQ:
finally scheduler for
parameters are defined by
Following
"
1. Number of queue required. of
queue. priority
algorithm for each increase and/or
decrease
for finding to
Scheduling
2. is required
3. Method
shortest-job-first
processes.
non preemptive versions of
FCFS, preemptive
and chart for the four
Explain the with Gantt
Example 2.6.8 2) schedulign
algorithms
(time slice = waitingtimp
and roudn robin average turn
around and
their
processes given. Compare
Burst tÉme
Arrival time
Process
10
P1
6
P2
2 12
P3
3 15
P4

TECHNICAL PUBLICATIONS -an up-thrust for knowledge


Introduction to Operating Systems 2- 44 Process Management

Solution: a) Gantt chart for FCFS :

P3 P4
P1 P2

16 28
10

b) Gantt chart for preemptive SJF:


P3 P4
P1 P2 P1
16 28 43
0 1 7

c) Gantt chart for non-preemptive SJF :

P3 P4
P1 P2
28 43
10 16

d) Gantt chart for round robin :

P1 P4 P2 P3 P1| P4 P3 P1 P3 P4 P3 P4 P4 P4 P4
P1 P2 P3 P1 P4 P2 P3

10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 4243
2 4 6 8

Waiting time
FCFS Preemptive SJF Nonpreemptive RR
Process
SJF
6 20
P1
0 13
P2

14 14 14 22
P3

P4 25 25 25 25

Average waiting time


0+9+14 +25 48
FCFS = = 12
4 4

6+0+14 +15 35
Preemptive SJF = = 8.75
4 4

0+9+14 +15 48
Nonpreemptive SJF = = 12
4 4

20 +13 + 22+ 25 80
RR = = 20
4 4

TECHNICAL PUBLICA TIONS an up-thrust for knowledge


2-45 Process Management
Introduction to Operating Systems

Turnaround time

FCFS Preemptive SJF Nonpreemptive RR


Process SJF

16 10 30
10
P1
15 19
15
P2 34
26
26
26
P3 40 40
40
40
P4

Average turnaround time


10+15+26+40 91 = 22.75
FCFS = 4 4

16+6+26+40 88 = 22
Preemptive SJF = 4
4

10+15+26+40 91 = 22.75
Nonpreemptive SJF= 4
4
30+19+34+ 40 123 = 30.75
RR = 4 4
following process
using
time for the
is the average turnaround
Example 2.6.9 What
non-prrmptive c) Preemptive SJF.
a) FCFS b) SJF Burst Time
Arrival Time
Process

0.0
P1
4
0.4
P2 Dec.-17, Marks 9
AU:

Solution : Gantt chart :

a) FCFS P3
P2
P1 13
8
12
0.0

b) SJF non-preemptive
P3 P2
|P1
8 13
0.0

TECHNICAL PUBLICA TIONs - an up-thrust for knowledge


Process Management
Introduction to Operating Systems 2-46

c) Preemptive SJF

P1 P2 P3 P2 |P1
13
1.0 2 5.6
0.0 0.4
Turnaround Time
Process
Process Waiting Time
FCFS SJF Preemptive
FCFS SJF Preemptive Non-preem SJF
Non-pree SJF ptive
mptive
8 13.2
5.2 P1
P1
11.6 12.6 5
8.6 1 P2
P2 7.6

P3 12
P3 11 7
7.2 9.53 6.4
Average
turnaround
time

University Questions

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

Process Burst Time Arrival Time

P1 0.00

P2 4 1.001

P3 2.001

P4 5 3.001

P5 4.001

Draw four Gantt charts illustrating the execution of these processes using FCFS, SJE, priority and
RR (quantum = 2) scheduling. Also calculate waiting timne and turnaround time for each
scheduling algorith1s. AU:May-17, Marks 13
2. Explain the differences in the degree to which the following scheduling algorithms discriminate in
favor of short process. :
i) RR i) Multilevel feedback queues. AU : May-18, Marks 13

TECHNICAL PUBLICATIONS an up-thrust for knowledge


2-47 Process Management
Introduction to Operating Systems

Consider the following set of processes, with the length of the CPU burst given in milliseconds :
Process Burst time Priority
10 3

P2 1 1

P3 2 3

PA 4

Ps 5 2

The process are assumed to have arrived in the order P, P, P3,, Pa, % all at time 0.
i) Draw Gantt chart that illustrate the execution of these processes using the scheduling algorithmns
FCFS (Smaller priority number implies higher priority) and RR (quantum = 1). [10]
ii) What is the waiting time of each process for each of the scheduling algorithms ? [5]
AU: May-18,22, Marks 15
4. Explain - multi level queue and multi level feedback queue scheduling with suitable examples.
AU: May-19, Marks 05

TECHNICAL PUBLICATIONS
an up-thrust for knowledge

You might also like