0% found this document useful (0 votes)
25 views5 pages

Term Paper

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)
25 views5 pages

Term Paper

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/ 5

A Comprehensive Study of CPU Scheduling

Algorithms
Pratik Kumar, Deepak Kumar, Lal Harshnath Shahdeo
B.Tech. Computer Science & Engineering, Lovely Professional University Phagwara, Punjab, India

ABSTRACT: In the operating system, Scheduling to scale back this overhead, the OS must schedule
of CPU plays a vital role in designing. The main the roles to urge the optimal utilization of CPU and
objective of our project is to compare different types to avoid the likelihood to deadlock.
of algorithms like First Come First Served
Scheduling, Shortest Job First Scheduling, Priority I. INTRODUCTION
Scheduling, Round Robin Scheduling, which helps Nowadays the operating system is more
us to improve the CPU efficiency and Timesharing complex, they are working on multitasking,
in the operating system. This paper depicts the study multiprocessing environment in which process is
of various scheduling algorithms for a CPU with the executed concurrently. The need for a scheduling
help of the Gantt chart. algorithm arises from the requirement for most
Why CPU scheduling? modern systems to perform multitasking (execute
In the uni-programming systems, when a process more than one process at a time) and
waits for an I/O operation, the CPU remains idle. multiprocessing (transmit multiple flows
This is an overhead and it wastes the time andcauses simultaneously). There are several scheduling
the problem of starvation. However, In algorithms available as FCFS (First Come First
Multiprogramming systems, the CPU doesn't remain Serve), SJF (Shortest Job First), Priority Scheduling,
idle during the waiting time of the Process and it and RR (Round Robin) scheduling algorithm. There
executes other processes. are some scheduling criteria, like turnaround time,
In Multiprogramming systems, the Operating response time, waiting time, and several contexts
system schedules the processes of the CPU to make switching based on these criteria we analyze and
maximum utilization of it and this is called CPU determine which scheduling algorithm is best. In this
scheduling. The Operating System uses various paper, we introduce basic CPU-scheduling concepts
scheduling algorithm to schedule the processes of and present several CPU-scheduling algorithms.
the CPU.
The short-term scheduler schedules the task of CPU II. ORGANIZATION OF THE PAPER
for the number of processes present in the JobPool. (Section iii) describes the dispatcher
Whenever the running process requests some I/O (section iv) describes the types of scheduling
operation then the short-term scheduler saves the (section v)
present context of the method called PCB and Describes the scheduling criteria (section vi)
changes its state from running to waiting. Now the describes various CPU scheduling algorithms with
process is in waiting state; the Short-term scheduler their Gantt charts (section vii) contains the
picks another process from the ready queue and conclusion (section viii) provides the references
assigns the CPU to the present process. This
procedure is named context switching. In III. CPU SCHEDULING: DISPATCHER
Multiprogramming, if the long-term scheduler has The dispatcher is one of the components
more I/O bound processes then most of the time, the involved in the CPU scheduling function. The
CPU remains idle. The task of OS is to optimize the dispatcher is a module that gives control to the CPU
use of resources. process selected by the short-term scheduler. The
If most of the running processes change their state functions are:
from running to waiting then there could also be an  Switching context
opportunity of deadlock within the system. Hence  Switching to user mode
 Jumping to the proper location in the user time). Considering a true system, CPU usage should
program to restart that program from where it range from 40% (lightly loaded) to 90%(heavily
left last time. loaded.)
The dispatcher should be as fast as 5.2 Throughput
possible, as long as it's invoked during every process It is the entire number of processes
switch. The time taken by the dispatcher to prevent completed per unit time or rather says the total
one process and start another process is Dispatch amount of labor done in a unit of your time. this
Latency. Dispatch Latency is often explained using might range from 10/second to 1/hour counting on
the below figure: the precise processes.
5.3 Turnaround Time
It is the quantity of your time taken to
execute a particular process, i.e. The interval from
the time of submission of the method to the time of
completion of the process (Wall clock time).
5.4 Waiting Time
The sum of the periods spent waiting
within the ready queue amount of your time a
process has been waiting within the ready queue to
accumulate get control on the CPU.
5.5 Load Average
It is the typical number of processes residing in the
ready queue expecting their address get into the
CPU.
IV. TYPES OF SCHEDULING. 5.6 Response Time
4.2 Medium-Term Scheduling The amount of your time it takes from when
Long-term scheduling performs like a
an invitation was submitted until the primary
gatekeeping function. It decides whether there is
response is produced. Remember, it's the time till the
enough memory, to allow jobs into the system. It primary response and not the completion of process
limits the process of multi-tasking to prevent slow
execution (final response). In common CPU
performance on current-running programs. When a
utilization and Throughput are maximized and other
job gets into the long-term scheduler, it is sent on to
factors are reduced for proper optimization.
the medium-term scheduler.
VI. SCHEDULING ALGORITHMS
4.2 Medium-Term Scheduling
To decide which process to execute first and which
process to execute last to achieve maximum CPU
The medium-term scheduler decides to
utilization, computer scientists have defined some
send a job to the sideline until a more important
algorithms, they are:
process is finalized. Later, when the computer has
less important jobs, the medium-term scheduler will  First Come First Serve (FCFS) Scheduling
allow the suspended job to pass.  Shortest-Job-First (SJF) Scheduling
 Priority Scheduling
4.3 Short-Term Scheduling  Shortest Remaining Time First (SRTF)
The short-term scheduler takes jobs from Scheduling
the "ready" line and it will execute to run with a  Round Robin (RR) Scheduling
green light. The short-term scheduler runs the  Highest Response Ratio Next (HRRN)
highest-priority jobs first and it makes on-the-spot Scheduling
decisions. For example, when a running process is  Multilevel Feedback Queue Scheduling
interrupted it may be changed, the short-term
scheduler must recalibrate and gives the green light 6.1 First Come First Serve (FCFS) Scheduling
for the highest-priority job. In the "First come first serve" scheduling
algorithm, because the name suggests, the method
V. 5.SCHEDULING CRITERIA which arrives first, gets executed first, or we will
5.1 CPU Utilization say that the method which requests the CPU first,
To make out the simplest use of CPU and gets the CPU allocated first.
to not waste any CPU cycle, CPU would be working  First Come First Serve, is simply like
most of the time(Ideally 100% of the FIFO(First in First out) Queue arrangement,
where the info element which is added to the To successfully implement it, the burst
queue first, is that the one who leaves the queue time/duration time of the processes should be known
first. to the processor beforehand, which is practically not
 This is employed in Batch Systems. feasible all the time.This scheduling algorithm is
 It's easy to know and implement perfect if all the jobs/processes are available at an
programmatically, employing a Queue equivalent time. (either time of arrival is 0 for all, or
arrangement, where a replacement process time of arrival is the same for all)
enters through the tail of the queue, and
therefore the scheduler selects a process from 6.2.1 Non-Preemptive Shortest Job First
the top of the queue. Consider the below processes available in the ready
 Poor in performance because the average wait queue for execution, with arrival time as 0 for all
time is high. and given burst times.
 A perfect real-life example of FCFS scheduling
is buying tickets at the ticket counter.
Consider the processes P1, P2, P3, P4 given in the
below table, arrives for execution in the same order,
with Arrival Time 0, and given Burst Time, let's find
the average waiting time using the FCFS scheduling
algorithm.

As you can see in the GANTT chart above,


the process P4 will be picked up first as it has the
shortest burst time, then P2, followed by P3 and at
last P1.
We scheduled the same set of processes using the
First Come First Serve algorithm in the previous
tutorial and got the average waiting time to be
The average waiting time will be 18.75 ms 18.75 ms, whereas, with SJF, the average waiting
For the above-given processes, first P1 will be time comes out 4.5 ms.
provided with the CPU resources,
6.1.2 Pre-emptive Shortest Job First
 Hence, the waiting time for P1 will be 0
In Preemptive Shortest Job First
 P1 requires 21 ms for completion, hence
Scheduling, jobs are put into the ready queue as they
waiting time for P2 will be 21 ms
arrive, but as a process with short burst time arrives,
 Similarly, the waiting time for process P3 will the existing process is preempted orremoved from
be the execution time of P1 + execution time for execution, and the shorter job is executed first.
P2, which will be (21 + 3) ms = 24 ms.
 For process P4 it will be the sum of execution
times of P1, P2, and P3.
The GANTT chart above perfectly represents the
waiting time for each process.

6.2 Shortest-Job-First(SJF) Scheduling


Shortest Job First scheduling works on the method
with the shortest burst time or duration first.This is
the best approach to attenuate waiting time.This is
employed in Batch Systems.It is of two types:
o Non-Preemptive
o Pre-emptive
As you can see in the GANTT chart that the
processes are given CPU time just based on the
As you can see in the GANTT chart above, priorities.
as P1 arrives first, hence its execution starts
immediately, but just after 1 ms, process P2 arrives 6.4 Shortest Remaining Time
with a burst time of 3 mswhich is less than the burst  Shortest remaining time (SRT) is that the
time of P1, hence the process P1(1 ms done, preemptive version of the SJN algorithm.
20 ms left) is preempted and process P2 is executed.  The processor is allocated to the work closest
As P2 is getting executed, after 1 ms, P3 to completion but it is often preempted by a
arrives, but it has a burst time greater than that of P2, more ready job with a shorter time to
hence the execution of P2 continues. But after completion.
another millisecond, P4 arrives with a burst time of  Impossible to implement in interactive systems
2 ms, as a result, P2(2 ms done, 1 ms left) is where required CPU time isn't known.
preempted and P4 is executed.  It is usually utilized in batch environments
After the completion of P4, process P2 is where short jobs got to give preference.
picked up and finishes, then P2 will get executed and
at last P1.
The Pre-emptive SJF is also known as Shortest
Remaining Time First because, at any given point
of time, the job with the shortest remaining time is
executed first.

6.3 Priority Scheduling


 Priority scheduling is a non-preemptive
algorithm and one among the foremost common
scheduling algorithms in batch systems.
 Each process is assigned a priority. Theprocess
with the highest priority is to be executed first
then on.
 Processes with the same priority are executed
on a first-come-first-served basis.
 Priority is often decided to support memory
requirements, time requirements, or the other 6.5 Round Robin(RR) Scheduling
resource requirement.
 Round Robin is the preemptive process
Consider the below table for processes with their scheduling algorithm.
respective CPU burst times and the priorities. Let the
 Each process is provided a fixed time to
arrival time be 0 for all the processes.
execute, it's called a quantum.
 Once a process is executed for a given time, it's
preempted and another process executes for a
given period.
 Context switching is employed to save lots of
states of preempted processes. 6.7 Multilevel Feedback Queue Scheduling
Consider all the process’s arrival time is 0. Multiple-level queues aren't an independent
scheduling algorithm. they create the use of other
existing algorithms to the group and schedule jobs
with common characteristics.
 Multiple queues are maintained for processes
with common characteristics.
 Each queue can have its scheduling algorithms.
 Priorities are assigned to each queue.
For example, CPU-bound jobs are often scheduled
in one queue, and each one I/O-bound jobs in
another queue. the tactic Scheduler then alternately
selects jobs from each queue and assigns them to the
CPU supported the algorithm assigned to the queue.
Here, the time quantum=5

6.6 Highest Response Ratio Next


(HRRN)Scheduling
 Highest Response Ratio Next (HRNN) is one of
the foremost optimal scheduling algorithms.
 This is a non-preemptive algorithm during
which, the scheduling is completed on the idea
of an additional parameter called Response
Ratio.
 A Response Ratio is calculated for every one of VII. CONCLUSION
the available jobs and therefore the Job with the The above mentioned are the different CPU
very best response ratio is given priority over scheduling utilized in this day. These algorithms are
the others. inherited supported by the need for the processor.
 Response Ratio is calculated by the given Scheduling algorithms shouldn't affect the behavior
formula.Response Ratio = (W+S)/S of the system (same results no matter schedule).
Where, However, the algorithms do impact the system's
W → Waiting Time efficiency and reaction time.
S → Service Time or Burst Time
REFERENCE
[1]. William Stallings, "Operating systems
Internals and Design Principles", 4th edition,
PHI, 2001.
[2]. https://www.wikipedia.org/
[3]. Silberschatz A., Peterson J.L and Galvin P.,
"Operating System Concepts", John Wiley
Publishing Company, 2002.
[4]. H.M.Deital, " An introduction to Operating
System", Pearson Education, 2001
when P1 enters, it gets executed. P2, P3, and P4 will [5]. Charles Crowley, "Operating System a Design
be waiting. After the execution of P1, the process Oriented Approach", Tata McGraw Hill,
with the highest response ratio must beexecuted. 2000.
RR(P2) = (21-1)+3/3=7.666 [6]. Milankovic M, "Operating System Concepts
RR(P3) = (21-2)+6/6=4.166 & Design", McGraw Hill,1999.
RR(P4) = (21-3)+2/2=10 [7]. ArmassDanesl, "Mastering Linux", Premium
Hence, P4 will be executed next since it has the Edition, BPB Publications, 1999.
highest response ratio.
RR(P2) = (23-1)+3/3=8.333
RR(P3) = (23-2)+6/6=4.5
P2 will be executed and then P3 will be executed.

You might also like