Module 3
Module 3
Module:3 Scheduling
Dr. P. Anandan
Mail: [email protected]
Mobile: 8056445321
Module:3 Scheduling
Dr.P.Anandan
Processes Scheduling & CPU Scheduling
Process / Job
Scheduling
Dr.P.Anandan
Job Scheduling vs CPU Scheduling
The CPU scheduling is the mechanism to
The job scheduling is the mechanism to
select which process has to be executed
select which process has to be brought
next and allocates the CPU to that
into the ready queue.
process.
Synonyms
The job scheduling is also known as the The CPU scheduling is also known as
long-term scheduling. short-term scheduling.
Processed By
The job scheduling is done by the long- The CPU scheduling is done by the short-
term scheduler or the job scheduler. term scheduler or the CPU scheduler.
Dr.P.Anandan
Scheduler
Schedulers are special system software that handles scheduling in various ways.
Their main task is to select the jobs to submit into the system and decide which
process to run. There are three types of schedulers in an operating system.
Dr.P.Anandan
Scheduling Queues
• Job Queue: As processes enter the system,
they are put into a job queue, which consists of
all processes in the system.
• Ready Queue: The processes that are residing
in main memory and are ready and waiting to
execute are kept on a list called the ready
queue.
Dr.P.Anandan
Different CPU times
• Arrival Time (AT):
Time at which the process arrives in Ready queue
• Completion time (CT):
Time at which the process complete its execution
• Burst Time (BT):
Process/CPU execution time
• Turn Around Time (TAT) : Difference between
submission of process and completion of process
(TAT) = CT – AT
Dr.P.Anandan
• Waiting time (WT):Time spent by process in
Ready Queue.
Waiting Time (WT) = TAT - BT
Dr.P.Anandan
Optimization Criteria
•Max CPU utilization
•Max throughput
•Min turnaround time
•Min waiting time
•Min response time
CPU scheduling decisions take place under one
of four conditions:
1. When a process switches from the running state to the
waiting state, such as for an I/O request or invocation
(Invoke) of the wait( ) system call.
2. When a process switches from the running state to the
ready state, for example in response to an interrupt.
3. When a process switches from the waiting state to the ready
state, say at completion of I/O or a return from wait( ).
4. When a process terminates.
Dr.P.Anandan
Pre-emptive scheduling Non-Preemptive
scheduling
• The currently running process • The running process
may be interrupted and moved to can only lose the
the ready state by OS (forcefully). processor voluntarily
by terminating or by
requesting an I/O.
Or
• Once CPU given to a
process it cannot be
preempted until the
process completes its
CPU burst.
Dr.P.Anandan
PREEMPTIVE NON-PREEMPTIVE
Parameter
SCHEDULING SCHEDULING
A low priority
process may starve if
If a process with a long burst time
a high priority
Starvation consumes CPU, subsequent processes
process often
with shorter burst times may suffer.
appears in the ready
queue.
Dr.P.Anandan
PREEMPTIVE NON-PREEMPTIVE
Parameter
SCHEDULING SCHEDULING
It contains overheads
There are no overheads in
Overhead associated with process
Non-preemptive scheduling.
scheduling.
Dr.P.Anandan
Pre-emptive Non-Preemptive
scheduling scheduling
Dr.P.Anandan
Non-Preemptive scheduling
1. First Come First Serve (FCFS)
•First Come, First Served (FCFS) also known as First In, First
Out(FIFO) is the CPU scheduling algorithm in which the CPU is
allocated to the processes in the order they are queued in the
ready queue.
•FCFS follows non-preemptive scheduling which mean once the
CPU is allocated to a process it does not leave the CPU until the
process will not get terminated or may get halted due to some
I/O interrupt.
•Buying a movie ticket from the ticket counter is a perfect real-
life example of a first come first serve (FCFS) algorithm. The
person who comes first and stands in the queue gets to buy the
ticket first. Similarly in the fcfs scheduling algorithm, the
process which arrives first gets executed first.
Dr.P.Anandan
Problem 1: Consider the set of 5 processes whose arrival time
and burst time are given below. Calculate the average TAT and
average WT if First Come First Serve (FCFS) scheduling
algorithm is followed
Process Burst Arrival
Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Process Name Burst Time Arrival Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Dr.P.Anandan
12/01/2023
Shortest Job First (SJF)(NPE)
Dr.P.Anandan
2. Shortest Job First (SJF)
• Shortest Job First (SJF) is an algorithm in
which the process having the smallest
execution time is chosen for the next
execution.
• This scheduling method can be preemptive or
non-preemptive. It significantly reduces the
average waiting time for other processes
awaiting execution
Dr.P.Anandan
• This algorithm method is helpful for batch-
type processing, where waiting for jobs to
complete is not critical.
• It can improve process throughput by making
sure that shorter jobs are executed first, hence
possibly have a short turnaround time.
• It improves job output by offering shorter jobs,
which should be executed first, which mostly
have a shorter turnaround time.
Dr.P.Anandan
Problem2. (SJF – Non Preemptive)
Consider the set of 5 processes whose arrival time and burst time
are given below. Calculate the average TAT and average WT if
SJF Non Preemptive scheduling algorithm is followed
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Ready Queue
Dr.P.Anandan
Dr.P.Anandan
Process Name Burst Time Arrival Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Dr.P.Anandan
3. Shortest Remaining Time First (SRTF)
(SJF – Preemptive)
• Preemptive version of SJF is known as Shortest
Remaining Time First (SRTF).
• In the Shortest Remaining Time First (SRTF)
scheduling algorithm, the process with the smallest
amount of time remaining until completion is
selected to execute.
Dr.P.Anandan
Problem3. (SJF – Preemptive)
Consider the set of 5 processes whose arrival time and burst time
are given below. Calculate the average TAT and average WT if
SJF Preemptive scheduling algorithm is followed
Dr.P.Anandan
Process Burst Arriva
Name Time l Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Dr.P.Anandan
Process Burst Arriva
Name Time l Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Dr.P.Anandan
Dr.P.Anandan
Dr.P.Anandan
Dr.P.Anandan
Process Burst Arriva
Name Time l Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
P1 2 6 15 15-2=13 13-6=7
P2 5 2 7 7-5=2 2-2=0
P3 1 8 23 23-1=22 22-8=14
P4 0 3 3 3-0=3 3-3=0
P5 4 4 10 10-4=6 6-4=2
Average 46/5=9.2 23/5=4.6
Dr.P.Anandan
4. Priority Scheduling (Non Preemptive)
(#lower value- Higher Priority)
• Before letting in the new process BT is
checked in SJF/SJN, here Priority is checked.
• In SJF/SJN after D execution, A got executed
next because BT of A (6) < BT of C (8).
• Now set the priority of C to #1 and A to #5,
remaining priority assign randomly.
Example: Priority Scheduling (Non Preemptive)
5. Priority Scheduling (Preemptive)
6. Round Robin Scheduling (Preemptive)
Ready
D C A D E C B A E C A C
Queue
PS – Round Robin – AT Zero
Dr.P.Anandan