0% found this document useful (0 votes)
45 views21 pages

OS UNIT3 SCHEDULING EXAPLES - Goswami

Uploaded by

Prayagi Ankit
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)
45 views21 pages

OS UNIT3 SCHEDULING EXAPLES - Goswami

Uploaded by

Prayagi Ankit
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/ 21

FCFS

Example: Here is an example of five processes arriving at


different times. Each process has a different burst time.

Process Burst time Arrival time

P1 6 2

P2 3 5

P3 8 1

P4 3 0

P5 4 4

Using the FCFS scheduling algorithm, these processes are


handled as follows.

Gantt Chart:

SANJAY GOSWAMI, OS…… Page 1


Process id Arrival Burst Waiting Turnaround
time time time time
P1 2 6 11-2=9 9+6=15 or
17-2=15
P2 5 3 21-5=16 24-5=19 or
16+3=19
P3 1 8 3-1=2 11-1=10

P4 0 3 0-0=0 3

P5 4 4 17-4=13 21-4=17

AvgWT=8 AvgTT=12.8

SJF (Non-Preemptive) or SJN


Advantages of SJF
1. Maximum throughput
2. Minimum average waiting and turnaround time (optimal)
Disadvantages of SJF
1. May suffer with the problem of starvation
2. It is not implementable because the exact Burst time for a
process can't be known in advance.

SANJAY GOSWAMI, OS…… Page 2


Example:

Process id Arrival Burst Waiting Turnaround


time time time time
P1 2 6 3-2=1 1+6=7
(9-2)
P2 5 3 9-5=4 4+3=7

P3 1 8 16-1=15 15+8=23
P4 0 3 0 0+3=3

P5 4 4 12-4=8 8+4=12

AvgWT = 5.6 AvgTT = 10.4

SANJAY GOSWAMI, OS…… Page 3


SJF (Preemptive) shortest remaining time
next (SRTN) / SRTF
In Preemptive SJF Scheduling, jobs are put into the ready queue
as they come. A process with shortest burst time begins
execution. If a process with even a shorter burst time arrives, the
current process is removed or preempted from execution, and
the shorter job is allocated CPU cycle.

Example: Consider the following five process:

Process Queue Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

SANJAY GOSWAMI, OS…… Page 4


Process id Arrival Burst Waiting Turnaround
time time time time
P1 2 6 10-1-2=7 7+6=13

P2 5 2 5-5=0 0+2=2

P3 1 8 15-1=14 14+8=22

P4 0 3 0 0+3=3

P5 4 4 7-1-4=2 2+4=6

Round Robin
No issues of starvation or convoy effect. Every job gets a fair
allocation of CPU. No priority scheduling is involved. Total
number of processes on the run queue helps assume the worst-case
response time for a process.
Every process gets an equal share of the CPU.

Example of Round-robin Scheduling


Consider this following three processes (Q=2 units)

Process Queue Burst time

P1 4

P2 3

SANJAY GOSWAMI, OS…… Page 5


P3 5

Gantt Chart:

WT (P1) = 6-2=4 TT(P1) = 4 + 4=8


WT(P2)= 8-2=6 TT(P2) = 6 + 3=9
WT(P3)=9-2=7 TT(P3) = 7 + 5 = 12
Avg WT =17/3 Avg TT=29/3
THROUGPUT = 3 / 12

EXAMPLE:
Process Arrival Burst WT WT WT TT TT TT
id time time SRTF RR RR
A 0 4 0
B 2 7 8-2=6

C 3 2 4-3=1

D 3 2 6-3=3

i) FCFS ii) SJF iii) SRTF iv) RR (Q=2, Q=1)


SANJAY GOSWAMI, OS…… Page 6
SRTF: Gantt chart:

SANJAY GOSWAMI, OS…… Page 7


RR (Q=2) Gantt chart:

WT(A)=4-2-0=2 TT(A)=2+4=6
WT(B)=10-2-2=6 TT(B)=6+7=13
WT(C)=6-3=3 TT(C)=3+2=5
WT(D)=8-3=5 TT(D)=10-3=7 OR (5+2)

RR (Q=1) Gantt chart:

WT(A)= 7-3-0=4 TT= (8-0)=8-4=4

SANJAY GOSWAMI, OS…… Page 8


WT(B)= 10-1-1-2=6 TT(B)=6+7=13 OR (15-2)
WT-C=8-1-3=4 TT = 4+2=6
WT-D=9-1-3=5 TT = 5+2=7
Example: Consider the set of 5 processes whose arrival time
and burst time are given below-

Process Id Arrival time Burst time

P1 0 5

P2 1 3

P3 2 1

P4 3 2

P5 4 3
If the CPU scheduling policy is Round Robin with time
quantum = 2 unit, calculate the average waiting time and
average turn around time.

SANJAY GOSWAMI, OS…… Page 9


Process Turn Around
Exit time Waiting time
Id time

13 – 5 = 8
P1 13 13 – 0 = 13
OR (12-2-2-0)

11 – 3 = 8
P2 12 12 – 1 = 11
(11-2-1)

P3 5 5–2=3 3–1=2

P4 9 9–3=6 6–2=4

P5 14 14 – 4 = 10 10 – 3 = 7

Avg TT = (13 + 11 + 3 + 6 + 10) / 5 = 43 / 5 = 8.6 unit


Avg WT = (8 + 8 + 2 + 4 + 7) / 5 = 29 / 5 = 5.8 unit

SANJAY GOSWAMI, OS…… Page 10


Priority Scheduling (Non Preemptive)
Advantages –
This provides a good mechanism where the relative importance
of each process maybe precisely defined.

Disadvantages –
If high priority processes use up a lot of CPU time, lower
priority processes may starve and be postponed indefinitely.
The situation where a process never gets scheduled to run is
called starvation.
Another problem is deciding which process gets which priority
level assigned to it.
Example: consider 4 processes with their burst times and
priorities. (Lower Number Represents Higher Priority. In
This Example).

SANJAY GOSWAMI, OS…… Page 11


Example: consider the set of 5 processes with their arrival time
and burst time. If the the CPU scheduling algorithm is non-
preemptive priority then calculate the average waiting time and
average turnaround time. (Higher number represents higher
priority)

Process Id Arrival time Burst time Priority

P1 0 4 2

P2 1 3 3

P3 2 1 4

P4 3 5 5

P5 4 2 5

SANJAY GOSWAMI, OS…… Page 12


Process Turn Around
Waiting time
Id time

P1 4–0=4 4–4=0

14 – 3 = 11
P2 15 – 1 = 14
(12-1)

P3 12 – 2 = 10 10 – 1 = 9

P4 9–3=6 6–5=1

P5 11 – 4 = 7 7–2=5

Avg TT = (4 + 14 + 10 + 6 + 7) / 5 = 41 / 5 = 8.2 unit


Avg WT= (0 + 11 + 9 + 1 + 5) / 5 = 26 / 5 = 5.2 unit

SANJAY GOSWAMI, OS…… Page 13


Priority Scheduling (Preemptive)
Consider the set of 5 processes whose arrival time and burst
time are given below-

Process Id Arrival time Burst time Priority

P1 0 4 2

P2 1 3 3

P3 2 1 4

P4 3 5 5

P5 4 2 5

If the CPU scheduling policy is priority preemptive, calculate


the average waiting time and average turnaround time. (Higher
number represents higher priority)

SANJAY GOSWAMI, OS…… Page 14


Process Turn Around
Exit time Waiting time
Id time

15 – 4 = 11
P1 15 15 – 0 = 15
(12-1-0)=11

P2 12 12 – 1 = 11 11 – 3 = 8

P3 3 3–2=1 1–1=0

P4 8 8–3=5 5–5=0

P5 10 10 – 4 = 6 6–2=4

SANJAY GOSWAMI, OS…… Page 15


Multilevel Queue Scheduling (MLQ):
Another class of scheduling algorithms has been created for situations in
which processes are easily classified into different groups.
For example, A common division is made between foreground(or
interactive) processes and background (or batch) processes. These two
types of processes have different response-time requirements, and so
might have different scheduling needs. In addition, foreground processes
may have priority over background processes.
A multi-level queue scheduling algorithm partitions the ready queue into
several separate queues. The processes are permanently assigned to one
queue, generally based on some property of the process, such as memory
size, process priority, or process type. Each queue has its own scheduling
algorithm.

A multilevel Queue with five queue is listed below according to


order of priority.

SANJAY GOSWAMI, OS…… Page 16


1. System Process Queue
2. Interactive Processes Queue
3. Interactive Editing Processes Queue
4. Batch Processes Queue
5. Student Processes Queue
Here, all queues have their own scheduling algorithm and
process is chosen with highest priority. Then it is executed
preemptive or non-preemptively. No process in lower priority
queue can get executed until higher process queue are all
empty.

SANJAY GOSWAMI, OS…… Page 17


For example, if batch process queue is running and interactive
process comes in ready state batch process is preempted and
interactive process is allowed to execute.

Advantages of Multilevel Queue Scheduling

With the help of this scheduling we can apply various kind of scheduling
for different kind of processes:
For System Processes: First Come First Serve(FCFS) Scheduling.
For Interactive Processes: Shortest Job First (SJF) Scheduling.
For Batch Processes: Round Robin(RR) Scheduling
For Student Processes: Priority Scheduling

Disadvantages of Multilevel Queue Scheduling

The main disadvantage of Multilevel Queue Scheduling is the problem


of starvation for lower-level processes.
Let us understand what is starvation?
Starvation:
Due to starvation lower-level processes either never execute or have to
wait for a long amount of time because of lower priority or higher
priority process taking a large amount of time.

SANJAY GOSWAMI, OS…… Page 18


Multilevel Feedback Queue Scheduling
(MLFQ):
In a multilevel queue-scheduling algorithm, processes are
permanently assigned to a queue on entry to the system and
processes are not allowed to move between queues.
As the processes are permanently assigned to the queue, this
setup has the advantage of low scheduling overhead,
But on the other hand disadvantage of being inflexible.

Advantages of Multilevel Feedback Queue Scheduling:


It is more flexible.
It allows different processes to move between different
queues.
It prevents starvation by moving a process that waits too
long for the lower priority queue to the higher priority
queue.

Disadvantages of Multilevel Feedback Queue Scheduling:


For the selection of the best scheduler, it requires some
other means to select the values.
It produces more CPU overheads.
It is the most complex algorithm.

Multilevel feedback queue scheduling, however, allows a


process to move between queues. Multilevel Feedback
Queue Scheduling (MLFQ) keeps analyzing the behavior (time
of execution) of processes and according to which it changes its
priority.

SANJAY GOSWAMI, OS…… Page 19


Now, let us consider multilevel feedback queue with three
queues.

1. A Round Robin queue with time quantum of 8 milliseconds,


say Q1.
2. A Round Robin queue with time quantum of 16 milliseconds,
say Q2.
3. A First Come First Serve queue, say Q3.
Now, when process enters Q1 it is allowed to execute and if
it not completes in 8 milliseconds it is shifted to Q2 and
receives 16 milliseconds. Again it is preempted to Q3 if it
not completes in 16 seconds. In this manner scheduling is
carried on in this scheme.

SANJAY GOSWAMI, OS…… Page 20


Example: Calculate waiting times and turnaround times for the
four processes with burst times below: (using Multilevel
Feedback Queue Scheduling for First level Queue with RR
quantum = 17, Second level Queue with RR quantum = 25
and last level FCFS queue, arrival times of all processes are
same.)

Process Id TT Burst time WT

P1 136 53 136-53=83

P2 34 17 34-17=17

P3 162 68 162-68=94

125-
P4 125 24
24=101

Gantt chart:

SANJAY GOSWAMI, OS…… Page 21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy