0% found this document useful (0 votes)
53 views53 pages

Multilevel Feedback Queue Scheduling

Uploaded by

nameistushar12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views53 pages

Multilevel Feedback Queue Scheduling

Uploaded by

nameistushar12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Chapter 3: Process Scheduling

CHAPTER 3: PROCESS SCHEDULING

□ Basic Concept
□ CPU-I/O burst cycle
□ CPU scheduler
□ Preemptive scheduling
□ Dispatcher
Basic Concepts
□ Scheduling is a important function of O.S.
□ In multiprogramming environment , many
process are in memory.
□ So CPU scheduling is necessary. By doing
CPU scheduling , O.S switching the CPU
from one process to other.
□ In a single processor system, only one process
can run until the CPU is free and can be
rescheduled.
Basic Concepts
□ The objective of multiprogramming is to have some process
running at all times to maximize CPU utilization.
□ The CPU executes one program at a time.
□ If that program requires I/O then O.S switches the CPU to
another ,This pattern continues.
□ Every time one process has to wait, another process can take
over use of the CPU.
□ Scheduling of this kind is a fundamental O.S function
□ Almost all computer resources are schedules before use.
CPU I/O BURST TIME
□ Maximum CPU utilization obtained with
multiprogramming
□ Process execution consists of a cycle of CPU
execution and I/O wait
□ Processes alternate between these two states.
□ Process execution begins with a CPU burst , that is
followed by an I/O burst, which is followed by
another CPU burst, then another I/O burst so on.
□ Eventually the final CPU burst ends with system
request to terminate execution
□ The duration of CPU burst vary from process to
process or computer to computer
□ If the program is I/O bound then it has short CPU
burst, when the program or process is CPU bound
then it has very short I/O burst.
□ This distribution is important in selecting
appropriate CPU scheduling algorithm
CPU SCHEDULER
□ Whenever the CPU becomes idle , the O.S must select one of the
processes in the ready queue to be executed.
□ The selection process is carried out by the short term scheduler (CPU
scheduler)
□ The scheduler selects a process from the processes in memory that
are ready to execute and allocates the CPU to that process.
□ The ready queue is not necessarily a FIFO queue. As we shall see when
we consider the various scheduling algorithm, a ready queue can be
implemented as a FIFO queue , a priority queue, a tree or simply an
unordered linked list.
□ Conceptually , however all the processes in the ready queue are lined
up waiting for a chance to run on the CPU.
□ The records in the queues are generally process control block of the
process.
PREEMPTIVE AND NON-PREEMPTIVE SCHEDULING

□ CPU scheduling decisions may take place under the


following four circumstances.
1. When a process switches from the running state to the
waiting state e.g. as the result of an I/O request or an
invocation of wait for the termination of one of the
child process.
2. When a process switches from the running state to the
ready state e.g. when an interrupt occurs.
3. When a process switches from the waiting state to the
ready state. E.g. at completion of I/O
4. When a process terminates.
PREEMPTIVE AND NON-PREEMPTIVE SCHEDULING
□ For situation 1 and 4 there is no choice in terms of
scheduling.
A new process (if one exists in the ready queue) must be
selected for execution.
There is a choice however for situations 2 and 3.
□ When scheduling takes place only under circumstances
1 and 4 we say that scheduling scheme is non-
preemptive or co-operative otherwise it is preemptive.
□ Under non-preemptive scheduling once the CPU has
been allocated to a process, the process keeps the
CPU until it release the CPU either by terminating or
by switching to the waiting state.
DISADVANTAGES

□ The scheduling cost is increased


□ When two processors are sharing same data if
one process is updating the data and at
that time the preemption occurs then it
will affect on the other process which
is reading same data
□ Preemption also has a affect on the design of
the
O.S kernel i.e. the important kernel data may
be changed.
DIFFERENCE BETWEEN PRE-EMPTIVE & NON-PRE-EMPTIVE
SCHEDULING
□ Pre-emptive Scheduling □ Non-pre-emptive Scheduling

1. Process switches from running state 1. Process switches from running state
to ready state to waiting state.
2. Also process switches from waiting 2. In this a process may get
state to ready state. terminated
3. Here, multiple process can run, one 3. In this when the process assigned to
process can be pre-empted to run CPU, it keeps process busy, till it gets
another process. terminated.
4. It needs specific Platform 4. It is platform independent (hardware
5. E.g. Windows 95 and MAC independent)
5. E.g. Windows 3.X versions.
DISPATCHER
□ Dispatcher module gives control of the CPU to
the process selected by the short-term
scheduler; this involves:
□ switching context
□ switching to user mode
□ jumping to the proper location in the user program to restart that
program

□ Dispatch latency – time it takes for the


dispatcher to stop one process and start
another running
SCHEDULING CRITERIA
□ Scheduler algorithm is one which selects some job from ready queue based on
some criteria and submit it to the CPU. In short it decides the sequence of
execution of the jobs.
□ The criteria includes the following:-
1. CPU utilization – It gives the information about how much time the CPU is
busy. It range from 0 to 100%. In real system it should range from 40% to
90%.
2. Throughput – If the CPU is busy executing processes, then work is being
done. One measure of work is the no. of processes that are completed per time
unit called throughput.
3. Turnaround time – From the point of view of a particular process, the
important criteria is how long it takes to execute that process. The interval
from the time of submission of a process to the time of completion is the
turnaround time.
Turnaround time=finish time-arrival time
4. Waiting time –It is amount of time a process has been waiting in the ready
queue. More waiting time more is the turn around time.
5. Response time – It is the time interval from submission of the job, to time
when the first response was produced.
SCHEDULING ALGORITHM

□ CPU scheduling deals with the problem of deciding which of


the processes in the ready queue is to be allocated the CPU.
□ The different scheduling algorithm are:-
1. FCFS (first come first serve)
2. SJF (shortest job first) – preemptive and non preemptive
3. Priority scheduling – preemptive and non preemptive
4. Round-robin scheduling
5. Multiple queue scheduling
6. Multilevel feedback queue scheduling


• To find out performance of the scheduling
algorithm we use Gantt chart .
• Gantt chart is nothing but a chart used to
describe a schedule. It will represent the
sequence in which the jobs will be scheduled
by the CPU.
FIRST-COME, FIRST-SERVED (FCFS) SCHEDULING

This algorithm selects first jobs or process for CPU .




It find out such process whose arrival time is smallest and then that selected

process is submitted to CPU for execution.
This algorithm only return the process number who come first to the dispatcher.
It is non-preemptive scheduling algorithm. Because when it started execution
of any process it should not stop execution in between or in middle.
So by default it act as a non-preemptive scheduling algorithm.
•Advantages of FCFS Algorithm
□ Simple and easy to use
□ Easy to understand
□ Easy to implement
□ Must be used for background process where execution is not urgent
•□
•Disadvantages of FCFS Algorithm
□ Suffer from convey effect (smaller process have to wait for long time for bigger
process to release CPU)
□ Normally higher average waiting time
□ No consideration to priority or burst time
□ Should not be used for interactive system
FCFS Gantt chart
p2 p1 p3
0 2 7 10

Proc Arriva CPU time Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P2 0 2 2 0 2

P1 1 5 7 1 6

P3 2 3 10 5 8

Total TWT=6 TTAT=16

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
FCFS Gantt chart

Proc Arriva CPU time Start Time Finish Time Waiting Time Turn Around
ess l time (or) burst ST FT WT=ST-AT Time
time (in ms) TAT=FT-AT

P1 0 2

P2 1 2

P3 4 3

P4 5 4

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
FCFS Gantt chart

Proc Arriva CPU time Start Time Finish Time Waiting Time Turn Around
ess l time (or) burst ST FT WT=ST-AT Time
time (in ms) TAT=FT-AT

P1 0 5

P2 0 10

P3 0 8

P4 0 3

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
FCFSGantt chart
P1
0
0 0
0
0
Proc Arriva CPU time Start Time Finish Time Waiting Time Turn Around
ess l time (or) burst ST FT WT=ST-AT Time
time (in ms) TAT=FT-AT

P1 0 2

P2 1 2

P3 5 3

P4 6 4

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
FCFS Gantt chart

0 3 4 9 13 17 19

Proc Arriva CPU time Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P1 4 5

P2 6 4

P3 0 3

P4 6 2

P5 5 4

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
FCFS Gantt chart

0 3 4 9 13 17 19

Proc Arriva CPU time Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P1 5 1

P2 6 0

P3 2 2

P4 4 0

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SHORTEST-JOB-FIRST (SJF) SCHEDULING
□ This algorithm selects job or process who has shortest burst time for CPU.
□ It find out such process whose burst time is smallest and then that selected process is submitted to CPU for
execution.
□ There are two types of the SJF algorithm
1)Non-preemptive SJF
2)Pre-emptive SJF

Non-Preemptive SJF Scheduling


□ When CPU is executing any process and during execution when any higher priority process
is entered in ready queue, then it will not stop the current execution, it completes its current
execution first and then it considers priority (shortest duration job) at the time of selection
of new process.
□ If smallest burst time of two processes are same then it selects process from smallest arrival
time.
□ If smallest burst time as well as arrival time of both the process are same then selection
depends on their process identification number.
Preemptive SJF Scheduling
□ When CPU is executing any process and during execution when any higher priority process is
entered in ready queue, then it will stop the current execution first and then considers priority
SHORTEST-JOB-FIRST
(SJF)SCHEDULING
Advantages of SJF Algorithm
□ Pre-emptive guarantees minimal average waiting time.

□ Provide a standard for other algorithm in terms of average waiting time


□ Due to short process first, its waiting time decreases and waiting time of long job increases
ultimately the waiting time decreases.
Disadvantages of SJF Algorithm
□ Algorithm cannot be implemented as there is no way to know the burst time of a process

□ Process with longer CPU burst time requirement will go into starvation

□ No idea of priority, process with large burst time have poor response time
SJF (non-preemptive )Gantt chart

Proc Arriva CPU time Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P1 1 3

P2 2 4

P3 1 2

P4 4 4

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SJF (non-preemptive )Gantt chart

0
Proc Arriva CPU time Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P1 2 2

P2 0 1

P3 2 3

P4 3 5

P5 4 4

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SJF (non-preemptive )Gantt chart

Proc Arriva CPU time Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P1 1.5 5

P2 0 1

P3 2 2

P4 3 4

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SJF (preemptive )Gantt chart

0
Pro Arriv CPU time CPU time Finish Time Waiting Turn
ces al (or) burst (or) burst Time Around
FT
s time time (in time (in Time
WT=TAT-BT
ms) ms) TAT=FT-
AT
P1 0 8

P2 1 4

P3 2 9

P4 3 5

Total TWT TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SJF (preemptive )Gantt chart

0 13
Proce Arrival CPU time CPU time Finish Time Waiting Time Turn Around
ss time (or) burst (or) burst FT WT=TAT-BT Time
time (in ms) time (in ms) TAT=FT-AT

P1 0 7
P2 1 5
P3 2 3
P4 3 1

P5 4 2
P6 5 1
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SJF (preemptive )Gantt chart

Proce Arrival CPU time CPU time Finish Time Waiting Time Turn Around
ss time (or) burst (or) burst Time
FT WT=TAT-BT
time (in ms) time (in ms) TAT=FT-AT

P1 2 1 1,0
P2 1 5 5
P3 4 1 1,0
P4 0 6 6,5,4

P5 2 3 3,2
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
SJF (preemptive )Gantt chart

0
Proce Arrival CPU time CPU time Finish Time Waiting Time Turn Around
ss time (or) burst (or) burst FT WT=TAT-BT Time
time (in ms) time (in ms) TAT=FT-AT

P1 2 1 1,0
P2 1 5 5
P3 4 1 1,0
P4 0 6 6,5,4
P5 2 3 3,2
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
PRIORITY SCHEDULING
□ Practically some processes require to run first even if they come late in the ready queue or even if
they requires large durations of the CPU
□ E.g. processes of the O.S compilers, assemblers, linker, loader etc.
□ So O.S require to assign them some priority no. So process scheduler can easily select the higher
priority process. So O.S can executes system properly and Smoothly.
□ A priority number (integer) is associated with each process

□ Two methods of priority Scheduling Algorithm


1. Pre-emptive
2. Non-pre-emptive

□ Problem ≡ Starvation – low priority processes may never execute

□ Solution ≡ Aging – as time progresses increase the priority of the process


PRIORITY CHEDULING

Advantages of SJF Algorithm


□ Provides a facility of priority specially for system process
□ Allows running important process first even if it is a user process.
□ Suitable for applications with varying time and resource requirement.

Disadvantages of SJF Algorithm


□ Here process with the smaller priority may starve for the CPU
□ In preemptive version context switch overhead is there.

□ Indefinite blocking or starvation. A process that is ready to run but lacking CPU
can be considered blocking or waiting for CPU.
□ In case if system crashes then all unfinished or pending low priority processes will
be lost.
Priority( Non preemptive) Gantt
chart

0
Proc Arriva CPU time Priority Finish Time Waiting Time Turn Around
ess l time (or) burst FT WT=TAT-BT Time
time (in ms) TAT=FT-AT

P1 0 5 3
P2 0 10 2
P3 0 8 4
P4 0 3 1(High)
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (NP) Gantt chart

P AT BT Priority FT WT=TAT-BT TAT=FT-AT

P1 0 8 3
P2 1 2 4
P3 3 4 4
P4 4 1 5
P5 5 6 2
P6 6 5 6
P7 10 1 1(high)
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (NP) Gantt chart

P AT BT Priority FT WT=TAT-BT TAT=FT-AT

P1 1 4 5
P2 2 5 2(low)
P3 3 6 6
P4 0 1 4
P5 4 2 7
P6 5 3 8(high)
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (Preemptive) Gantt
chart

P AT BT BT Priority FT WT=TAT-BT TAT=FT-AT

P1 1 4 5

P2 2 5 2(low)
P3 3 6 6
P4 0 1 4

P5 4 2 7
P6 5 3 8(high)
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (Preemptive) Gantt
chart

P AT BT BT Priority FT WT=TAT-BT TAT=FT-AT

P1 0 5 10

P2 1 4 20
P3 2 2 30
P4 4 1 40(high)

Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (Preemptive) Gantt
chart

P AT BT BT Priority FT WT=TAT-BT TAT=FT-AT

P1 0 5 4
P2 2 4 2
P3 2 2 6(L)
P4 4 4 3
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (Preemptive) Gantt
chart

P AT BT BT Priority FT WT=TAT-BT TAT=FT-AT

P1 0 8 4
P2 1 6 6
P3 3 7 3
P4 3 9 1(h)
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Priority (Premptive) Gantt chart

0
P AT Priority BT BT FT WT=TAT-BT TAT=FT-AT

P1 0 3 8
P2 1 4 2
P3 3 4 4
P4 4 5 1
P5 5 2 6
P6 6 6(L) 5
P7 10 1(H) 1
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
ROUND ROBIN (RR)
□ When all modern electronics components are used in the computer system speed of computer is
increased , size of computer is decreased and capacity of processor itself is also increases. So the
concept of multiuser O.S is introduced with round robin scheduling.
□ Which is explained as follows.
1. This scheduler divide execution time into small but fixed time slices called as a time quantum or
time slots.
2. It assign these time slots to each process present in the ready queue and execute process within
that slots only
3. Ready queue is kept as a FIFO queue.
4. When time quantum of first process is over then it performs following actions.
5. It calls dispatcher and it takes following actions.
-> It stores old content of the internal register, program counter and current resource status in the
PCB.
-> It find out new process for execution from ready queue.
-> Reload the content into the program counter and internal register from the PCB of that new
process.
ROUND ROBIN (RR)
Advantages of SJF Algorithm
□ The average waiting time is minimal.

□ Works well in case of time sharing system, client server architecture and
interactive system.
Disadvantages of SJF Algorithm
□ If the time quantum is too large then it is as good as FCFS policy

□ Longer process may go into starvation

□ Performance depends heavily on time quantum

□ No idea of Priority.
Round Robin (time Quantum=2) Gantt chart

0
Proce Arrival CPU time CPU time Finish Time Waiting Time Turn Around
ss time (or) burst (or) burst FT WT=TAT-BT Time
time (in ms) time (in ms) TAT=FT-AT

P1 0 5
P2 1 3
P3 2 1
P4 3 2

P5 4 3
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
Round Robin (time Quantum=3) Gantt chart

0
Proce Arrival CPU time CPU time Finish Time Waiting Time Turn Around
ss time (or) burst (or) burst FT WT=TAT-BT Time
time (in ms) time (in ms) TAT=FT-AT

P1 0 8
P2 5 2
P3 1 7
P4 6 3

P5 8 5
Total TWT= TTAT=

Average Waiting Time = TWT/no of process=


Average TAT = TTAT/no of process =
MULTILEVEL QUEUE
□ In this processes are easily classified into different groups. E.g A common division is made
where Ready queue is partitioned into separate queues, eg:
□ foreground (interactive)
□ background (batch)
□ These two types of processes have different response time, requirements and so
may have different scheduling needs
□ 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:


□ foreground – RR
□ background – FCFS
□ Scheduling must be done between the queues:
□ Each queue has jobs with some common property.
□ Priority are specified for the queue
□ One by one all queues are processed in descending order of priority
MULTILEVEL QUEUE
□ Job assigned to a queue remain permanently in the same queue. They are not
allowed to move from one queue to other.
□ Until and unless all jobs from high priority queue are not over, scheduling for
low priority do not start.
□ Sometimes a fixed time slot is given to each job
□ While scheduling a particular job, if any high priority job entered the queue,
then current job is preempted. Therefore this scheduling is also called as fixed
priority pre-emptive scheduling
□ Each queue has absolute priority over lower priority queue
□ No process in the batch queue e.g could run unless the queue for system
processes, interactive and interactive editing processes were all empty
□ If an interactive editing process entered the ready queue while the batch process
was running the batch process would be preempted.
MULTILEVEL QUEUE SCHEDULING
MULTILEVEL FEEDBACK QUEUE
● This allows to move process between queues. The idea is to separate processes
according to the characteristics of their CPU burst.
● If a process uses too much CPU time, it will be moved to a lower priority
queue
● In addition, a process that waits too long in a lower priority queue may
be moved to a higher priority queue
● Consider a multilevel feedback queue scheduler with 3 queue, numbered from 0
to 2
● The scheduler first executes all processes in queue 0
● Only when queue 0 is empty will be execute processes in queue 1
● Similarly processes in queue 2 will only be executed if queue 0 and 1 are empty
● A process that arrives for queue 1 will in turn be preempted by a process
arriving for queue 0
MULTILEVEL FEEDBACK QUEUE
● A process entering the ready queue is put in queue 0
● A process in queue 0 is given a time quantum of 8 millisecond
● If it does not finish within this time it is moved to the tail of queue1
● If queue 0 is empty the process at the head of queue 1 is given a time
quantum of 16 milliseconds
● If it does not complete it is preempted and is put into queue 2
● Process in queue 2 are run on an FCFS basis but can run only when queue 0
and 1 are empty
EXAMPLE OF MULTILEVEL FEEDBACK QUEUE

Queue 0

Queue 1

Queue 2
END OF CHAPTER 3

You might also like