Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
CPU SCHEDULING
CPU Scheduling is a process of determining
which process will own CPU for execution while
another process is on hold.
The main task of CPU scheduling is to make sure
that whenever the CPU remains idle, the OS at
least select one of the processes available in the
ready queue for execution.
The selection process will be carried out by the
CPU scheduler. It selects one of the processes in
memory that are ready for execution.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
CPU Scheduling Terminologies
Burst Time/Execution Time: It is a time required by the process
to complete execution. It is also called running time.
Arrival Time: when a process enters in a ready state.
Finish Time: when process complete and exit from a system.
Multiprogramming: A number of programs which can be
present in memory at the same time.
Jobs: It is a type of program without any kind of user
interaction.
User: It is a kind of program having user interaction.
Process: It is the reference that is used for both job and user.
CPU/IO burst cycle: Characterizes process execution, which
alternates between CPU and I/O activity. CPU times are usually
shorter than the time of I/O.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
What is Important in a Scheduling Algorithm?
Minimize Response Time
Elapsed time to do an operation (job)
Response time is what the user sees
Time to compile a program
Real-time Tasks: Must meet deadlines imposed by
world.
Maximize Throughput
Jobs per second
Throughput related to response time, but not identical
Minimizing response time will lead to more context
switching than if you maximized only throughput
Minimize overhead (context switch time) as well as
efficient use of resources (CPU, disk, memory, etc.)
Share CPU among users in some equitable way
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Scheduling Criteria:
CPU Utilization: CPU utilization refers to a computer's usage of
processing resources, or the amount of work handled by a CPU.
Throughput: Number of processes executed per unit time.
Turnaround Time: Time interval from the time of submission
of a process to the time of the completion of the process.
Waiting Time: The amount of time the process spends in the
ready queue waiting for the CPU
Waiting Time: Turnaround Time - Burst Time
Response Time: It is the time between submission of requests
and first response to the request.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
CPU Scheduling Algorithm:
There are mainly six types of process scheduling
algorithms:-
First Come First Serve (FCFS)
Shortest-Job-First (SJF) Scheduling
Shortest Remaining Time
Priority Scheduling
Round Robin Scheduling
Multilevel Queue Scheduling
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
First Come First Serve Scheduling [FCFS]
First Come First Serve is the full form of FCFS. It is the easiest
and most simple CPU scheduling algorithm. In this type of
algorithm, the process which requests the CPU gets the CPU
allocation first. This scheduling method can be managed with a
FIFO queue.
As the process enters the ready queue, its PCB (Process Control
Block) is linked with the tail of the queue. So, when CPU
becomes free, it should be assigned to the process at the
beginning of the queue.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
First Come First Serve Scheduling [FCFS]
In this scheduling, the process that requests the CPU first, is
allocated the CPU first.
Thus, the name First-Come-First-Served.
The implementation of FCFS is easily managed with a FIFO
queue.
First Come First Serve Scheduling [FCFS]
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
First Come First Serve Scheduling [FCFS]
When a process enters the ready queue, its PCB
is linked to the tail of the queue.
When CPU is free, it is allocated to the process
which is at the head of the queue.
FCFS scheduling algorithm is non-preemptive.
Once the CPU is allocated to a process, that
process keeps the CPU until it releases the CPU,
either by terminating or by I/O request.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Example of FCFS Scheduling
Suppose that the processes arrive in the order: P1, P2, P3.
The Gantt Chart for the schedule is:
Waiting Time for P1 = 0 milliseconds
Waiting Time for P2 = 24 milliseconds
Waiting Time for P3 = 27 milliseconds
P1 P2 P3
0 27
24 30
P1 24
P2 3
P3 3
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Characteristics of FCFS Scheduling:
It is the simplest form of a CPU Scheduling Algorithm.
Jobs are always executed on a first-come, first-serve basis.
It is easy to implement and use.
However, this method is poor in performance, and the
general wait time is quite high.
Characteristics of FCFS Scheduling:
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Merits and Demerits of FCFS Scheduling
Merits:
More predictable than other schemes since it offers time.
Code for FCFS scheduling is simple to write and
understand.
Demerits:
Short jobs(process) may have to wait for long time.
Important jobs (with higher priority) have to wait.
Cannot guarantee good response time.
Average waiting time and turn around time is often quite long.
Lower CPU and device utilization.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Shortest Job First Scheduling (SJF)
SJF (Shortest Job First) is a scheduling algorithm in
which the process with the shortest execution time
should be selected for execution next. This scheduling
method can be preemptive or non-preemptive. It
significantly reduces the average waiting time for other
processes awaiting execution.
• This scheduling algorithm is optimal if all the
jobs/processes are available at the same time.
• It is the best approach to minimize the waiting time.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Characteristics of SJF Scheduling:
It is associated with each job as a unit of time to complete.
In this method, when the CPU is available, the next process
or job with the shortest completion time will be executed
first.
It is implemented with non-preemptive policy.
This algorithm method is useful for batch-type processing,
where waiting for jobs to complete is not critical.
It improves job output by offering shorter jobs, which
should be executed first, which mostly have a shorter
turnaround time.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Merits and Demerits of SJF Scheduling
Merits:
1. SJF is basically used for Long Term Scheduling.
2. The average waiting time of Shortest Job First (SJF) is less than
the FCFS (First-Come, First Serve) algorithm.
3. For a particular set of processes, SJF provides the lowest average
waiting
4. In terms of the average turnaround time, it is optimal.
Demerits:
1. Sometimes the problem of starvation occurs in SJF.
2. SJF needs the knowledge to know how long a process will run.
3. It is not easy to know the upcoming CPU request length.
4. In SJF, it is necessary to record elapsed time, resulting in more
overhead the processor.
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Pre-emptive Scheduling
Preemptive Scheduling is a CPU scheduling technique that works
by dividing time slots of CPU to a given process. The time slot given
might be able to complete the whole process or might not be able
to it. When the burst time of the process is greater than CPU cycle,
it is placed back into the ready queue and will execute in the next
chance. This scheduling is used when the process switch to ready
state. The tasks are mostly assigned with their priorities
Algorithms that are backed by preemptive Scheduling are
round-robin (RR), priority, SRTF (shortest remaining time first).
The lower priority task holds for some time and resumes when
the higher priority task finishes its execution.
Pre-emptive Scheduling
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Non-preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to
a specific process. The process that keeps the CPU busy will
release the CPU either by switching context or terminating. It is
the only method that can be used for various hardware
platforms.
That’s because it doesn’t need special hardware (timer) like
preemptive scheduling. No process is interrupted until it is
completed, and after that processor switches to another process.
Algorithms based on non-preemptive scheduling are: Shortest
Job First, Priority Scheduling.
Non-preemptive Scheduling
Reaccredited by
NAACwith A+
Presidency
Group
Presidency
College
(Autonomous)
Purpose of CPU Scheduling
• The CPU uses scheduling to improve its efficiency.
• It helps you to allocate resources among competing
processes.
• The maximum utilization of CPU can be obtained with multi-
programming.
• The processes which are to be executed are in ready queue.