Professional Documents
Culture Documents
In preemptive scheduling, a running process may be replaced by a higher priority process any
time. This is accomplished by activating the scheduler whenever an event that changes the state
of the system is detected.
Commonly used processor scheduling algorithms
A process scheduler schedules different processes to be assigned the processor based on a
particular scheduling algorithms. The most common process scheduling algorithms include:
First Come First Served (FCFS) or First In First Out (FIFO)
First-In-First Out (FIFO) also known as First Come First Served (FCFS) is the simplest
scheduling algorithm. As the name implies, the processes are executed in the order of their
arrival in the ready queue, which means the process that enters the ready queue first gets the
CPU (processor) first. FCFS is non-preemptive scheduling algorithm.
Therefore, once a process gets the CPU (processor), it retains the control of the CPU (processor)
until it blocks or terminates. The implementation of a FCFS scheduling algorithm is achieved
through a ready queue, which is easily managed as a First in First Out (FIFO) queue as shown in
the diagram below
When the first process enters the ready queue, it immediately gets the CPU (processor), and
starts executing. Meanwhile, other processes enter the system and are added to the end of the
queue by inserting their PCBs in the queue. When the currently running process completes or
blocks, the CPU is allocated to the process at the head of the ready queue and its PCB is removed
from the queue. In case a currently running process was blocked and later transits into the ready
state, it joins the ready queue at the tail, i.e. Its PCB is linked to the end of the ready queue.
Characteristics
It is a non-preemptive scheduling algorithm.
It is fair since all processes are treated equally i.e. each process is given processor time.
It is unfair since unimportant processes make important processes wait.
It is bias to short jobs since long processes make short processes wait
It is easy to understand and implement
Its implementation is based on FIFO queue.
Processes are executed on first come, first served basis.
Poor in performance as average wait time is high.
Advantages
First-In-First Out (FIFO) algorithm does not include any complex logic, it just places
process requests in a queue and executes them one by one.
It is simple and easy to implement as processes are simply to be added at the tail and
removed from the head of the ready queue.
It is non-preemptive hence once a process starts executing it runs to completion without
any interruptions.
Starvation does not occur, since eventually, every process will get a chance to run.
It is well suited for batch systems where the longer time periods for each process are
often acceptable.
Disadvantages
It is unfair since unimportant processes make important processes wait.
It is bias to short jobs since long processes make short processes wait
It is bias to short jobs since long processes make short processes wait resulting in lower
CPU (processor) utilization.
The average waiting time is not minimal and therefore it is not applicable where
performance is a major issue.
It is not suitable for time sharing systems where each process should get the same amount
of CPU (processor) time.
It reduces the CPU and I/O devices utilization under some circumstances, e.g. where
there are a long CPU bound process and many short I/O bound processes.
Adding the execute time for each process to the time the previous process completed gives the
time when the next process to be allocated for the processor begins to execute and hence the
Gantt chart showing the order of execution will look like the diagram below:
1. Since the operating system uses the First-In-First Out (FIFO scheduling algorithm and
process P0 has the least arrival time, it will be allocated the processor first and will start
executing at 0 unit time. It will spend 5 unit time in the processor (execution time or CPU
burst time) to complete at 5 unit time.
2. Process P1 is the second process to be allocated for the processor since it has the second
least arrival time i.e. 1 and will start executing at 5-unit time. It will spend 3 unit time in
the processor to complete at 8 unit time.
3. Process P2 is the third process to be allocated for the processor since it has the third least
arrival time i.e. 2 and will start executing at 8-unit time. It will spend 8 unit time in the
processor to complete at 16-unit time.
4. Finally, process P3 is the last process to be allocated for the processor since it has the
highest arrival time i.e. 2 and will start executing at 16-unit time. It will spend 6-unit time
in the processor to complete at 22 unit time.
The turnaround time
Turnaround time of each process is as follows:
Process Turnaround time = Terminate time – Arrival time
P0 5–0=5
P1 8– 1 = 7
P2 16 – 2 = 14
P3 22 – 3 = 19
The average turnaround time
Average wait time = (5+7+14+19)/4 = 11.25 unit time
1. Since the operating system uses the First-In-First Out (FIFO scheduling algorithm and
process P1 has the least arrival time i.e. 0, it will be allocated the processor first and will
start executing at 0 unit time. It will spend 15 ms in the processor (execution time or CPU
burst time) to complete at 15 ms.
2. Process P2 is the second process to be allocated for the processor since it has the second
least arrival time i.e. 2 and will start executing at 15 ms. It will spend 6 unit time in the
processor to complete at 21 ms.
3. Process P3 is the third process to be allocated for the processor since it has the third least
arrival time i.e. 3 and will start executing at 21 ms. It will spend 7 unit time in the
processor to complete at 28 ms.
4. Finally, process P4 is the last process to be allocated for the processor since it has the
highest arrival time i.e. 5 and will start executing at 28 ms. It will spend 5 ms in the
processor to complete at 33 ms.
Hence:
The turnaround time
Turnaround time of each process is as follows:
Process Turnaround time = Terminate time – Arrival time
P1 33 – 5 = 28
P2 11 – 2 = 9
P3 18 – 3 = 15
P4 5–0=5
The average turnaround time
Average wait time = (28+9+15+5)/4 = 14.25 ms
The wait time
Wait time of each process is as follows:
Process Wait time = Turnaround time – CPU burst time (Execute time)
P1 28 – 15 = 13
P2 9–6=5
P3 15 – 7 = 8
P4 5 – 15= -10
The average wait time
Average wait time = (13+5+8+10)/4 = 6 ms
Note: Ignore the negative sign in P4’s wait time
It is clear that if the processes having shorter CPU burst execute before those having longer CPU
burst, the average waiting and turnaround time reduces significantly.
Practice exercise one
The table below shows four processes: P1, P2, P3, P4 and P5. The operating system uses First-In-
First Out (FIFO) scheduling algorithm.
Required:
i. Draw a Gantt chart to show the order of execution
ii. Calculate the wait time for each process and eventually the average wait time
iii. Calculate the turnaround time for each process and eventually the average turnaround
time
Practice exercise two
The table below shows details of FCFS scheduling algorithm. Use it to answer the question that
follow
Process Arrival time Execution time Service time
P0 0 5 0
P1 1 3 5
P2 2 8 8
P3 3 6 16
Required:
i. Calculate the wait time for each process labeled P0, P1, P2 and P3
ii. Calculate the average wait time for all the processes.
iii. Draw a Gantt chart to show the order of execution
iv. Calculate the turnaround time for each process labeled P0, P1, P2 and P3
v. Calculate the turnaround time for all the processes.
Practice exercise three
The table below shows different processes and their respective burst times during inter process
communication. Use it to answer the questions that follow
Suppose the processes arrive at time 0 in the order P2, P4, P1 and P3 respectively.
Required:
Assuming the First In First Out (FIFO) scheduling algorithm:
i. Draw a Gantt chart to show the order of execution
ii. Calculate the wait time for each process labeled P1, P2, P3 and P4
iii. Calculate the average wait time for all the processes.
iv. Calculate the turnaround time for each process labeled P1, P2, P3 and P4
v. Calculate the turnaround time for all the processes.
Shortest Job First (SJF) scheduling
The Shortest Job First also known as Shortest Process Next (SNP), Short Job Next (SJN) or
Shortest Request Next (SRN), is a non-preemptive scheduling algorithm that schedules the
processes according to the length of CPU burst, execute time or runtime they require. At any
point in time, among all the ready processes, the one having the shortest (smallest) CPU burst,
execute time or runtime is scheduled first.
Thus, a process has to wait until all the processes shorter than it have been executed. This tends
to reduce the number of waiting processes and also the number of processes waiting behind large
processes.
Note:
In case two processes have the same CPU burst, execute time or runtime, they are
scheduled in the FCFS order.
Shortest Job First is of two types, Non-preemptive and preemptive. The preemptive
version of Shortest Job First scheduling is known as Shortest Remaining Time
Characteristics
It favours short processes.
It is a non-preemptive scheduling algorithm
It selects processes for service in a manner ensuring the next one will complete and the
leave the computer system as soon possible.
It reduce the number of waiting processes and also the number of processes waiting
behind large processes.
It selects the job with the shortest service time hence is bias to long jobs.
The processor should know in advance how much time a process will take.
It is optimal if all the jobs/processes are available at the same time i.e. all processes either
arrival time is 0 for all, or arrival time is the same for all
Advantages
It favours short processes and eliminates the bias against them experienced in First-In-
First Out (FIFO) algorithm.
Throughput is increased since more processes can be executed in a lesser amount of time.
It is easy to implement in batch systems where required processor time is known in
advance.
It eliminates the variance in waiting and turnaround times.
It minimizes average waiting and turnaround time
Disadvantages
It is difficult to implement as it needs to know the length of CPU burst of processes in
advance. In practice, having the prior knowledge of the required execute time of
processes is difficult.
It is bias towards processes having longer CPU burst. This is because as long as the short
processes continue to enter the ready queue, the long processes will not be allowed to get
the CPU. This results in starvation of long processes
Longer processes and thus they will have more waiting time and eventually suffer
starvation.
Elapsed time i.e., execution-completed-time must be recorded, it results to an additional
overhead on the processor.
12 Complied by Mr. P.K Munene
Process Management - Lesson 3 – Scheduling algorithms
allocated the processor first since it has the least arrival time i.e. 0 and process P1 will be the
second process to be allocated the processor since it has the least execute time i.e. 3.
More so, if all the processes arrive at the time then only the CPU burst time or execute time is
considered with the process with the least CPU burst time or execute time being allocated for the
processor first.
The amount of time a process spends in a processor is determined by the process’s execute time
or CPU burst time. The execute time also determines the time the execution of the next process
to be allocated for the processor begins, bearing in mind that it is only the first process to be
allocated for the processor whose execution time begins at the zero mark unless otherwise stated
while all others do not.
Adding the execute time for each process to the time the previous process completed gives the
time when the next process to be allocated for the processor begins to execute and hence the
Gantt chart showing the order of execution will look like the diagram below:
1. Since the operating system uses the non-preemptive version of Shortest Job Next (SJN)
scheduling algorithm and process P0 has the least arrival time i.e. 0 it will be allocated the
processor first and will start executing at 0 unit time. It will spend 5 unit time in the
processor (execution time or CPU burst time) to complete at 5 unit time.
2. Process P1 is the second process to be allocated for the processor since it has the least
execute time i.e. 3 and will start executing at 5 unit time. It will spend 3 unit time in the
processor to complete at 8 unit time.
3. Process P3 is the third process to be allocated for the processor since it has the second
least execute time i.e. 6, ignoring Process P0 since it was the first to be allocated for the
processor and will start executing at 8 unit time. It will spend 6 unit time in the processor
to complete at 14 unit time.
4. Finally, process P2 is the last process to be allocated for the processor since it has the
third highest execute time and will start executing at 14 unit time. It will spend 8-unit
time in the processor to complete at 22 unit time.
1. Since the operating system uses the Shortest Job First (SJF) scheduling algorithm and
process P1 has the least arrival time i.e. 0, it will be allocated the processor first and will
start executing at 0-unit time. It will spend 7 ms in the processor (execution time or CPU
burst time) to complete at 7 ms.
2. Process P3 is the second process to be allocated for the processor since it has the least
execute time i.e. 2 and will start executing at 7 ms. It will spend 2 unit time in the
processor to complete at 9 ms.
3. Process P4 is the third process to be allocated for the processor since it has the second
least execute time i.e. 3 and will start executing at 9 ms. It will spend 3-unit time in the
processor to complete at 12 ms.
4. Finally, process P2 is the last process to be allocated for the processor since it has the
third least execute time i.e. 5 and will start executing at 12 ms. It will spend 5 ms in the
processor to complete at 17 ms.
The turnaround time
Turnaround time of each process is as follows:
Process Turnaround time = Terminate time – Arrival time
P1 7–0=7
P2 17 – 1 = 16
P3 9–3=6
P4 12 – 4 = 8
The average turnaround time
Average wait time = (7+16+6+8)/4 = 9.25 ms
The wait time
Wait time of each process is as follows:
Process Wait time = Turnaround time – CPU burst time (Execute time)
P1 7–7=0
P2 16 – 5 = 11
P3 6–2=4
P4 8–3=5
The average wait time
Average wait time = (0+11+4+5)/4 = 5 ms
Practice exercise one
A computer system has a set of five processes P1, P2, P3, P4 and P5 on the queue and which arrive
at time 0, in that order. Each of the processes has a CPU burst time shown in the table below. Usr
it to answer the questions that follow
Required:
i. Draw a Gantt chart to show the order of execution
ii. Calculate the wait time for each process and eventually the average wait time, assuming a
non-preemptive Shortest Job First (SJF) scheduling algorithm.
iii. Calculate the turnaround time for each process and eventually the average turnaround
time
Practice exercise two
The table below shows details in a computer system. Use it to answer the questions that follow
Process Arrival time Run time
W 0 2
X 2 7
Y 2 20
Z 3 3
Required:
i. Draw a Gantt chart to show the order of execution
ii. Calculate the wait time for each process and eventually the average wait time, assuming a
non-preemptive Shortest Job First (SJF) scheduling algorithm.
iii. Calculate the turnaround time for each process and eventually the average turnaround
time.
iv. Explain three advantages of the system
Advantages
Processes have short CPU burst time hence execute fast.
Average turnaround time is less.
Disadvantages
Long burst (CPU bound) processes have increased mean waiting time hence long
processes may suffer starvation.
Difficult to implement since CPU burst time must be known in advanced or estimated
and this is difficult to do.
A running process, which has run almost to completion, may be preempted by a new job
with a very small run time creating an unnecessary overhead.
Class exercise one
The table below shows five processes: P1, P2, P3 and P4. Draw a Gantt chart to show the order of
execution. Calculate the turnaround time for each process and eventually the average turnaround
time. Calculate the wait time for each process and eventually the average wait time. The
operating system uses Shortest Remaining Time (SRT) scheduling
Process Arrival time CPU burst time
P1 0 21
P2 1 5
P3 2 6
P4 3 2
Solution:
The Gantt chart
Since the operating system is using a preemptive version of Shortest Job Next (SJN) or Shortest
Remaining Time (SRT) scheduling algorithm then, the order in which the processor will be
allocated to the processes is determined by the processes individual remaining execute time with
the process with the least remaining execute time being allocated for the processor first.
However a running process can be preempted by a newly arriving process whose execute time is
smaller than the remaining execute time of the currently running process. In the case above,
process P1 will be allocated the processor first since it has the least arrival time i.e. 0 and process
P2 will be the second process to be allocated the processor since it has the second least arrival
time i.e. 1. However, on the arrival of process P2, the remaining execute time for process P1 will
1. Since the operating system uses the preemptive version of Shortest Job Next (SJN) or
Shortest Remaining Time (SRT) scheduling algorithm and P1 has the least arrival time i.e.
0, it will be allocated the processor first and will start executing at 0 unit time.
2. After 1 ms, process P2 arrives with a burst time of 5 ms which is less than the burst time
of process P1, hence the process P1 with 1 ms done, 20 ms left, is preempted and
process P2 is allocated for the processor and beings to execute.
3. After 1 ms, of executing process P2, process P3 with a burst time of 6 ms which is greater
than the remaining burst time of process P2, arrives. Thus, process P3 does not preempt
process P2 and process P2 continue to execute.
4. After another 1 ms of executing process P2, process P4 with a burst time of 2 ms which is
less than the remaining burst time of process P2, arrives. As a result P2 with 2 ms done, 3
ms left is preempted and P4 is allocated for the processor and beings to execute.
5. Process P4 runs to completion to complete at 5 ms.
(tail) of the ready queue to wait a second quantum and this continues until the process
runs to completion.
In Round Robin scheduling, the principal design issue is the length of the time quantum or time-
slice to be used. If the quantum is very short, then short processes will move quickly. In the
figure below process, P1 is dispatched to a processor, where it executes either until completion,
in which case it exists the system or until its time slice expires, at which point it is preempted and
placed at the tail of the ready queue. The scheduler then dispatched process P2.
Preemption
Characteristics
Advantages
Round Robin is effective in a general-purpose, times-sharing system or transaction-
processing system.
Each process is served by the processor for a fixed time quantum, so all processes are
given the same priority.
23 Complied by Mr. P.K Munene
Process Management - Lesson 3 – Scheduling algorithms
Starvation does not occur since in each round robin cycle, each process is given a fixed
time to execute.
Overhead on processor is low
Good response time for short processes.
Disadvantages
The throughput in RR largely depends on the choice of the length of the time quantum. If
time quantum is longer than needed, it tends to exhibit the same behavior as First Come
First Served (FCFS).
If time quantum is shorter than needed, the number of times that the processor switches
from one process to another process, increases. This leads to decrease in processor
efficiency.
Care must be taken in choosing quantum value.
Processing overhead is there in handling clock interrupt.
Throughput is low if time quantum is too small.
with respect to the context switch time. This is to ensure that a process keeps CPU for a
maximum time as compared to the time spent in the context switching.
Class exercise one
The table below shows four processes: P0, P1, P2 and P3. Use it to calculate the wait time for
each process and eventually the average wait time. Draw a Gantt chart to show the order of
execution. Calculate the turnaround time for each process and eventually the average turnaround
time. The operating system uses round robin scheduling algorithm and the quantum = 4
Process Arrival time Execute time Service time
P1 1 3 24
P2 2 8 3
P3 3 6 3
Solution:
The wait time
Wait time of each process is as follows:
Adding the execute time for each process to the time the previous process completed gives the
time when the next process to be allocated for the processor begins to execute and hence the
Gantt chart showing the order of execution will look like the diagram below:
1. Using a time quantum of 4-unit time, then process P1 is allocated for since it has the least
arrival time i.e. 1 and is runs for the first quantum but does not run to completion since it
requires another 20-unit time to complete (service time – first quantum), hence it is
preempted after the first quantum and placed at the tail of the ready queue to await the a
second allocation of the processor (second quantum)
2. The processor is allocated to the next process in the queue, process P2 since it has the
second least arrival time i.e. 2. Process P2 does not need 4 unit time to run completion
since its service time is 3 hence it completes before its quantum expires and exits the
system.
3. The processor is allocated to the next process, process P3 since it has the third least arrival
time i.e. 3. Process P3 also does not need 4 unit time to run to completion since its service
time is 3 hence it completes before its quantum expires and exits the system.
4. The processor is allocated to process P1 for an additional time quantum. On the expiry of
the second quantum it is immediately allocated a third, fourth, five and six quantum since
it is the only runnable process in the ready queue, to run to completion.
Note:
In Round Robin scheduling algorithm, no process is allocated the processor for more than
one-time quantum in a row unless it is the only runnable process in the ready queue.
If a process’s service time exceeds one-time quantum, that process is preempted and
placed at tail of the ready queue.
Draw a Gantt chart to show the order of execution. Calculate the average waiting time and
average turnaround time. The operating system uses the Round Robin (RR) scheduling.
Priority scheduling
In priority scheduling, a priority (an integer) is associated with each process and the processor is
always allocated to the process with the highest priority. Priority of a process represents its
likelihood of being scheduled next. Generally, the smallest integer is considered to be the highest
priority. Equal priority processes are scheduled in First Come First serve order. Priorities are
assigned to processes by the user or the system at process creation time and may be of two types
namely:
Static priorities: These are priorities that remain fixed i.e. they do not change easily,
they remain the same for a fixed period of time and are not responsive to changes in the
environment.
Dynamic priorities: These are priorities that are responsive to changes in the
environment or changing need and are easy to implement.
When a scheduling selection is to be made, the scheduler starts at the highest priority ready
queue RQ0. There is one or more processes in the queue, a process is selected using some
scheduling policy. If RQ0 is empty, then RQ1 is examined, and so on as shown in the diagram
below
A common problem with priority based scheduling is the possibility that low priority processes
maybe effectively locked out by the higher priority ones. A solution to this problem is aging
priority, in which the priority of each process is gradually increased after the process spends a
certain amount of time in the system. Eventually the older process attains high priority and are
assured of processor time. This act is known as aging and its purpose is to prevent indefinite
postponement of processes.
Characteristics
Advantages
The priority of a process can be selected based on memory requirement, time requirement
or user preference. For example, a high end game will have better graphics, which means
the process, which updates the screen in a game, will have higher priority to achieve
better graphics performance.
Good response for the highest priority processes
Disadvantages
A second scheduling algorithm is required to schedule the processes which have same
priority.
In preemptive priority scheduling, a higher priority process can execute ahead of an
already executing lower priority process. If lower priority process keeps waiting for
higher priority processes, starvation occurs.
Class exercise one
The table below shows four processes: P0, P1, P2 and P3. Use it to calculate the wait time for
each process and eventually the average wait time. Draw a Gantt chart to show the order of
execution. Calculate the turnaround time for each process and eventually the average turnaround
time. The operating system uses priority-scheduling algorithm
to be allocated for the processor begins to execute and hence the Gantt chart showing the order
of execution will look like the diagram below:
1. Since the operating system uses the priority scheduling algorithm P0 or P2 will be
considered first since they have the least priority value (integer) i.e. 1 hence the highest
priority.
2. Since processes with the same priority are executed on a first come first served basis P0
will be allocated for the processor first since P0 since it has the least amount of arrival
time i.e. 0 as compared to that of P2 which is 2 and will start executing at 0 unit time. It
will spend 5 unit time in the processor (execution time or CPU burst time) to complete at
5 unit time.
3. Process P3 will be allocated the processor next since, although it has an equal priority
with process P0, it has the second least arrival time i.e. 2 and will start executing at 5 unit
time. It will spend 8 unit time in the processor (execution time or CPU burst time) to
complete at 13 unit time.
4. Process P2 will be allocated the processor next since it has the second least priority value
(integer) i.e. 2 and will start executing at 13 unit time. It will spend 3 unit time in the
processor (execution time or CPU burst time) to complete at 16 unit time.
5. Finally, process P3 will be allocated the processor last since it has the highest priority
value (integer) i.e. 3 and will start executing at 16 unit time. It will spend 6 unit time in
the processor (execution time or CPU burst time) to complete at 22 unit time.
Practice exercise
The table below shows four processes: P0, P1, P2 and P3. Use it to calculate the Response Ratio
for each process. Draw a Gantt chart to show the order of execution. Calculate the turnaround
time for each process and eventually the average turnaround time. The operating system uses
Highest Response Ration Next (HRRN) scheduling.
Process Arrival time Execute time Wait time Service time
P0 0 5 3 3
P1 1 3 0 0
P2 2 8 14 16
P3 3 6 5 8
Multilevel queue scheduling
Multilevel queue scheduling algorithm partitions the ready queue into separate queues. The
processes are permanently assigned to one queue, depending on their properties such as the size
of memory or the type of the process. Each queue uses a different independent scheduling
algorithm, e.g. the ready queue can be portioned into three ready queues. One ready queue for
system processes, one for interactive processes (foreground processes) and one for batch
processes (background processes).
The system processes ready queue may follow the Shortest Job First (SJF) scheduling algorithm,
the interactive processes ready queue may follow the Round Robin (RR) scheduling algorithm
while the batch processes ready queue may follow the First Come First Served (FCFS)
scheduling algorithm as shown in the diagram below
The idea is to separate process with different CPU burst characteristics. The process scheduler
then alternatively selects processes from each queue and assigns them to the processor based on
the algorithm assigned to the queue. The system processes ready queue has the highest priority of
all and the batch process ready queue has the lowest priority of all, each queue has absolute
priority over the lower priority queues.
This means that no process in the batch queue could run unless the queues for system processes
and interactive processes are empty. If it happens that an interactive process enters the ready
queue while a batch process is running, then the batch process is preempted.
Characteristics
Multiple queues are maintained for processes with common characteristics.
Each queue can have its own scheduling algorithms.
Priorities are assigned to each queue.
Advantages
As each type of process is in a different queue, it is easier to execute high priority
processes first without incurring additional overhead.
Disadvantges
No process in the lower queue can be executed unless all upper queues are empty. If a
higher priority process enters the ready queue while a lower priority process is running
then the lower priority process is preempted. This leads to starvation.
Multilevel Feedback Queue Scheduling (MLFQ)
The Multilevel Feedback Queue scheduling algorithm allows a process to move between the
queues. Rather than have fixed classes of processes allocated to specific queues, each process
may start at the top level queue. A new process enters the queuing network at the tail of the
highest queue, assigned the highest priority and lowest quantum. The process progresses through
that queue in First In First Out (FIFO) order until the process obtains a processor.
If the process completes it execution, or it relinquishes the processor to wait for an I/O
completion, it exists the queuing network. If a process’s quantum expires before the process
voluntarily relinquishes the processor, the operating system preempts it, places it at the tail of the
next lower level queue, reduces it priority and increases it quantum.
As long as the process uses the full quantum provided at each level and does not complete by
then, it continues to move to the tail of the next lower level queue, its priority being reduced and
its quantum being increased as shown in the diagram below
Usually, there is some bottom level queue through which the process circulates round robin until
it completes. The process that next gets the processor is the one at the head of the highest non-
empty queue in the multilevel feedback queue.
Since a running process is preempted by one arriving in a higher queue, a process in a lower
queue can suffer indefinite postponement, if a higher queue always contains at least one process.
Since the scheduler increases a process’s quantum size as the process moves to each lower level
queue, the longer the process has been in the queuing network, the larger the quantum it receives
each time it obtains the processor. Now, look at the diagram and explanation below to
understand it properly.
Assuming that queue 1 and 2 follow round robin with time quantum 4 and 8 respectively and queue
3 follows FCFS. One implementation of MFQS is given below:
P1 P2 P1 P2 P3 P4 P3
4 6 15 20
0 2 7 10
1. Since the operating system uses the Multilevel Feedback Queue scheduling algorithm and
queue 1 is of a higher priority than queue 2 then processes P1 and P2 will be considered
first since they are both in queue 1 and hence have the highest priority. However, process
P1 has the least arrival time hence it is allocate for the processor before P2 and will start
executing at 0 ms. It will spend 2 ms ( allowable quantum time) in the processor
(execution time or CPU burst time) to be preempted at 2 ms since the allowable quantum
time expires.
2. Process P2 will be allocated for the processor next since, it is in queue 1 and has the
second least arrival time and will start executing at 2 ms. It will spend 2 ms ( allowable
quantum time) in the processor (execution time or CPU burst time) to be preempted at 4
ms since the allowable quantum time expires.
3. Process P1 will again be allocated for the processor to run for a second allowable quantum
and will start executing at 4 ms. It will spend 2 ms (allowable quantum time) in the
processor (execution time or CPU burst time) to complete at 6 ms since it required only
two allowable quantum i.e. 4 ms to run to completion.
4. Process P2 will again be allocated for the processor to run for a second allowable quantum
and will start executing at 6 ms. It will spend 1 ms in the processor (execution time or
CPU burst time) to complete at 7 ms since it required only one and a half allowable
quantum i.e. 3 ms to run to completion and it completes before its second quantum
expires.
5. Process P3 will be allocated for the processor next since, it is in queue 2 and there is no
process in queue 1. It will start executing at 7 ms, however after only one and a half
allowable quantum i.e. 3 ms it is preempted because process P4 arrives at queue 1 which
is of a higher priority than queue 2.
6. Process P4 will be allocated for the processor next and will start executing at 10 ms. It
will spend two and half allowable quantum i.e. 5 ms in the processor (execution time or
CPU burst time) to complete at 15 ms.
7. Finally, process P3 will be allocated for the processor and will start executing at 15 ms.
However, it had previously run for one and a half allowable quantum i.e. 3 ms and
currently requires only two and half allowable quantum i.e. 5 ms to run to completion.
Thus, It will spend 5 ms in the processor (remaining execution time or CPU burst time) to
complete at 20 ms
The turnaround time
Turnaround time of each process is as follows:
Process Turnaround time = Terminate time – Arrival time
P1 6–0=6
P2 7–1=6
P3 20 – 2 = 18
P4 15 – 10 = 5
The average turnaround time
Average wait time = (6+6+18+5)/4 = 8.75 ms
The wait time
Wait time of each process is as follows:
Process Wait time = Turnaround time – CPU burst time (Execute time)
P1 6–4=2
P2 6–3=3
P3 18 – 8 = 10
P4 5–5=0
The average wait time
Average wait time = (2+3+10+0)/4 = 3.75 ms
Practice exercise
Consider four processes P1, P2, P3 P4 and with their required CPU burst (in milliseconds) and
priority queues as shown in the following table:
Priority of queue 1 is greater than queue 2. Queue 1 has a Time Quantum (TQ) of 4 and queue 2
has a Time Quantum (TQ) of 3. Draw a Gantt chart to show the order of execution. Calculate the
turnaround time for each process and eventually the average turnaround time. Calculate the wait
time for each process and eventually the average wait time.
Load balancing
Load balancing is the process of evenly distributing the workload across all processors so as to
ensure that no one processor is overworked while another underworked or idle. Scheduling
algorithms are also known as load balancing methods.
Goals of load balancing
Load balancing aims to
Optimize resource use.
Maximize throughput.
Minimize response time.
Avoid overload of any single resource.
Avoid crashing of the system.