Term Paper
Term Paper
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.