SlideShare a Scribd company logo
Prof. Deptii Chaudhari
HOPE FOUNDATION’S
INTERNATIONAL INSTITUTE OF INFORMATION TECHNOLOGY, (I²IT)
www.isquareit.edu.in
+91 20 22933441 / 2
Scheduling Algorithms
• CPU scheduling deals with the problem of deciding which of the
processes in the ready queue is to be allocated the CPU.
• There are many different CPU scheduling algorithms.
• First Come First Serve Scheduling (FCFS)
• Shortest Job First Scheduling (SJF)
• Round Robin Scheduling (RR)
• Priority Based Scheduling
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
First Come First Serve Scheduling (FCFS)
• By far the simplest CPU-scheduling algorithm is the first-come, first-served
(FCFS) scheduling algorithm.
• With this scheme, the process that requests the CPU first is allocated the CPU
first.
• The implementation of the FCFS policy is easily managed with a FIFO
queue.
• When a process enters the ready queue, its PCB is linked onto the tail of the
queue. When the CPU is free, it is allocated to the process at the head of the
queue.
• The running process is then removed from the queue.
• FCFS is non preemptive i.e.Process continues to run till the burst cycle ends
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
FCFS Example
Process Arrival Time Burst Time
P1 0 7
P2 0 4
P3 0 2
P4 0 5
Arrival Time: When Process enters Ready
Queue
Burst Time: Time Required by the process for
execution
Average Waiting Time = (0+7+11+13)/4
= 7.75
Average Response Time = (0+7+11+13)/4
= 7.75
(Same as Average Waiting Time)
Gnatt Chart : Horizontal bar chart developed
by Henry Gantt, an American Engineering and
social scientist in 1917 as a production control
tool
P1 P2 P3 P4
Response Time = Time taken
by a particular process to
begin executing on CPU –
Time it enters in ready queue.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
• Order of Scheduling matters
Process Arrival Time Burst Time
P1 0 7
P2 0 4
P3 0 2
P4 0 5
P1P2 P3 P4
Average Waiting Time
= (0+4+6+11)/4
= 5.25
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Convoy Effect
• All processes wait for the one
big process to get off the
CPU
Process Arrival Time Burst Time
P1 0 7
P2 0 4
P3 0 2
P4 0 5
P1 P2 P3 P4
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
FCFS - Advantages & Disadvantages
• Advantages
• Simple
• Fair ( as long as no process hogs the CPU, every process will
eventually run)
• Disadvantages
• Waiting time depends on arrival order
• Short processes stuck waiting for long process to complete
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Shortest Job First (SJF)
• A different approach to CPU scheduling is the shortest-job-first (SJF)
scheduling algorithm.
• This algorithm associates with each process the length of the process's next
CPU burst.
• When the CPU is available, it is assigned to the process that has the smallest
next CPU burst.
• If the next CPU bursts of two processes are the same, FCFS scheduling is used
to break the tie.
• No preemption : the process continues to execute until its CPU burst
completes
• With preemption : the process may get preempted when a new process arrives
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
SJF ( without preemption)
Average wait time
= (7+3+1+0) / 4 = 2.75
Average Response Time
= (Average wait time)
Process Arrival Time Burst Time
P1 0 7
P2 0 4
P3 0 2
P4 0 1
Schedule
P1
P2
P3
P4
P4 P3 P2 P1
Arrival
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
SJF ( without preemption)
Average Wait Time
= (0+8+4+0)/4
= 3
Average Response Time
= (Average Wait Time)
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 2
P4 7 1
P1 P4 P3 P2Schedule
Arrival P1 P2 P3 P4
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
SJF – Advantages & Disadvantages
• Advantages
• Optimal : Minimum average wait time
• Disadvantages
• Not Practical : difficult to predict burst time (learning to
predict future)
• May starve long jobs
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Round Robin (RR)
• The round-robin (RR) scheduling algorithm is designed especially for
timesharing systems.
• It is similar to FCFS scheduling, but preemption is added to switch
between processes.
• A small unit of time, called a time quantum or time slice, is defined. A
time quantum is generally from 10 to 100 milliseconds.
• The ready queue is treated as a circular queue. The CPU scheduler goes
around the ready queue, allocating the CPU to each process for a time
interval of up to 1 time quantum.
• To implement RR scheduling, we keep the ready queue as a FIFO queue of
processes.
• New processes are added to the tail of the ready queue. The CPU scheduler
picks the first process from the ready queue, sets a timer to interrupt after 1
time quantum, and dispatches the process.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Round Robin Scheduling
P1 P2 P3 P4 P1 P2 P4 P1
P2
P3
P4
P3
P4
P1
P4
P1
P2
P1
P2
P2
P4
P4
P1
P1
Process Arrival Time Burst Time
P1 0 5
P2 0 4
P3 0 2
P4 0 3
Schedule
FIFO
Time Slice =2
Average Wait Time = (9+8+4+10)/4 =7.75
Average Response Time = (0+2+4+6)/4 =3
No of Context Switch = 7
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Round Robin Scheduling
P1 P2 P3 P4
P1 P1 P2 P3 P1 P2 P4 P1
P2 P2
P3
P3
P1
P1
P2
P2 P2
P4
P4
P1
P1
Process Arrival
Time
Burst
Time
P1 0 7
P2 2 4
P3 3 2
P4 9 1
Schedule
FIFO
Arrival
Average Waiting Time = (7+6+3+3)/4 = 4.75
Average Response Time = (0+2+3+3)/4 = 2
No of Context Switches = 6
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Round Robin Scheduling
Process Arrival
Time
Burst
Time
P1 0 7
P2 2 4
P3 3 2
P4 9 1
P1 P2 P3 P4
P1 P1 P2 P1 P3 P2 P1 P3 P2 P1 P4 P2 P1
P2 P1
P3
P3
P2
P2
P1
P1
P3
P3
P2
P2
P1
P1
P4
P4
P1
P2
P1
P1
Schedule
FIFO
Arrival
Average Waiting Time = (7+7+4+2)/4 = 5
Average Response Time = (0+1+2+2)/4 = 1.25
No of Context Switches = 11
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Round Robin Scheduling (Larger Timeslice)
Process Arrival
Time
Burst
Time
P1 0 7
P2 2 4
P3 3 2
P4 9 1
P1 P2 P3 P4
P1 P2 P3 P1 P4 P3
P2 P2
P3
P2
P3
P3
P1
P3
P1
P3
P1
P3
P1
P1
P4
P4
P3
P4
P3
P3
Schedule
FIFO
Arrival
Average Waiting Time = (5+3+9+3)/4 = 5
Average Response Time = (0+3+6+3)/4 = 3
No of Context Switches = 5
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Duration of Timeslice
• Duration of time slice is very critical.
• It affects both response time as well as number of context switches.
• A short quantum timeslice
• Good, because processes need not wait long before they are
scheduled
• Bad, because context switch overhead increases
• A long quantum timeslice
• Bad, because processes no longer appear to execute concurrently
• May degrade system performance
• Timeslice is typically kept between 10ms to 100ms
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Round Robin – Advantages & Disadvantages
• Advantages
• Fair – Each process gets a fair chance to run on CPU
• Low average wait time
• Faster response time
• Disadvantages
• Increased context switching – Context switches are overhead
• High average wait time, when burst times have equal lengths
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Shortest Remaining Time First (SRTF)
• Preemptive SJF scheduling is sometimes called shortest-
remaining-time-first scheduling.
• In SRTF scheduling, if a new process arrives with a shorter burst
time than remaining of current processes then schedule new
process.
• It further reduces the average waiting time and average response
time.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Shortest Remaining Time First (SRTF)
Process Arrival
Time
Burst
Time
P1 0 7
P2 2 4
P3 4 2
P4 7 1
Schedule
Arrival P1 P2
P1
P2 burst time is 4,
P1 remaining burst time is 5
(Preempt P1)
P3 burst time is 2,
P2 remaining burst time is 2
(No Preemption)
P3
P2 P3
P4
P1
Average Wait Time
= (7+0+2+1)/4
= 2.5
Average Response Time
= (0+0+2+1)/4
=0.75
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Priority Based Scheduling
• Each process is assigned a priority.
• A priority is a number in a range (e.g 0 to 255)
• A small number would mean high priority and larger number would
mean low priority
• Scheduling policy : Pick the process from the ready queue having
the highest priority
• Advantage: Provides relative importance to processes
• Disadvantage: Could lead to starvation of low priority processes.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Priority Based Scheduling
P2 P1 P4 P3
0 3 24 26
Process Priority Burst
Time
P1 2 21
P2 1 3
P3 4 6
P4 3 2
Average Waiting Time
= (0+3+24+26)/4
= 13.25
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Priority Based Scheduling
P2 P5 P1 P3 P4
Process Burst
Time
Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
0 1 6 16 18 19
Average Waiting Time
= (6+0+16+18+1)
= 8.2
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Priority Based Scheduling
• Priority scheduling can be either preemptive or non-preemptive.
• When a process arrives at the ready queue, its priority is compared
with the priority of the currently running process.
• A preemptive priority scheduling algorithm will preempt the CPU if
the priority of the newly arrived process is higher than the priority
of the currently running process.
• A non-preemptive priority scheduling algorithm will simply put the
new process at the head of the ready queue.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Priority Scheduling – Drawbacks
• A major problem with priority scheduling algorithms is indefinite
blocking, or starvation.
• A process that is ready to run but waiting for the CPU can be considered
blocked.
• A priority scheduling algorithm can leave some low priority processes
waiting indefinitely.
• In a heavily loaded computer system, a steady stream of higher-priority
processes can prevent a low-priority process from ever getting the CPU.
Generally, one of two things will happen.
• Either the process will eventually be run (when the system is finally
lightly loaded), or the computer system will eventually crash and lose all
unfinished low-priority processes.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Solution to Starvation - Ageing
• A solution to the problem of indefinite blockage of low-priority
processes is aging.
• Aging is a technique of gradually increasing the priority of
processes that wait in the system for a long time.
• For example, if priorities range from 127 (low) to 0 (high), we
could increase the priority of a waiting process by 1 every 15
minutes.
• Eventually, even a process with an initial priority of 127 would
have the highest priority in the system and would be executed.
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
THANK YOU !!
For further information please contact
Prof. Deptii Chaudhari
Department of Computer Engineering
Hope Foundation’s International Institute of Information Technology, I2IT
Hinjawadi, Pune – 411 057
Phone - +91 20 22933441
www.isquareit.edu.in | deptiic@isquareit.edu.in
Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057
Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

More Related Content

PDF
Process scheduling (CPU Scheduling)
PPTX
2.2. language evaluation criteria
PPT
Fundamentals of the Analysis of Algorithm Efficiency
PPT
Operating Systems Process Scheduling Algorithms
PPTX
Performance analysis(Time & Space Complexity)
PPTX
Dining Philosopher Problem
PDF
Time and Space Complexity
PPT
Real-Time Scheduling
Process scheduling (CPU Scheduling)
2.2. language evaluation criteria
Fundamentals of the Analysis of Algorithm Efficiency
Operating Systems Process Scheduling Algorithms
Performance analysis(Time & Space Complexity)
Dining Philosopher Problem
Time and Space Complexity
Real-Time Scheduling

What's hot (20)

PPTX
Scheduling Definition, objectives and types
PDF
Daa notes 1
PPTX
Message passing in Distributed Computing Systems
PPTX
Os unit 3 , process management
PPT
message passing
PPTX
Memory management ppt
PPTX
Unit 1. Problem Solving with Computer
PPTX
contiguous memory allocation.pptx
PDF
03 Analysis of Algorithms: Probabilistic Analysis
PPT
Scheduling algorithms
PPTX
Shortest Job First
PDF
OS - Process Concepts
PPT
Algorithmic Notations
PPTX
Intermediate code generator
PPTX
Leaky Bucket & Tocken Bucket - Traffic shaping
PDF
Design and analysis of algorithms
PPTX
SCHEDULING ALGORITHMS
PPTX
daa-unit-3-greedy method
Scheduling Definition, objectives and types
Daa notes 1
Message passing in Distributed Computing Systems
Os unit 3 , process management
message passing
Memory management ppt
Unit 1. Problem Solving with Computer
contiguous memory allocation.pptx
03 Analysis of Algorithms: Probabilistic Analysis
Scheduling algorithms
Shortest Job First
OS - Process Concepts
Algorithmic Notations
Intermediate code generator
Leaky Bucket & Tocken Bucket - Traffic shaping
Design and analysis of algorithms
SCHEDULING ALGORITHMS
daa-unit-3-greedy method
Ad

Similar to Operating System Scheduling Algorithms (20)

PDF
OS Process Chapter 3.pdf
PPTX
Presentation by adeel
PPTX
Operating Systems CPU Scheduling and its Algorithms
PPT
Ch05 cpu-scheduling
PPTX
Cpu scheduling
PPTX
Scheduling Algorithms-Examples.pptx
PPTX
Week 5a.pptx of cpu scheduling operating system class
PPTX
Scheduling Algorithm in System Designing.pptx
PDF
CPU Scheduling Part-II.pdf
PPTX
Operating systems - Processes Scheduling
PPT
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
PDF
CPU Scheduling
PPT
Cpu scheduling
PPTX
CPU scheduling
PPTX
UNIPROCESS SCHEDULING.pptx
PPTX
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
PPTX
3Chapter Three- CPU Scheduling this is the best.pptx
PDF
CPU Scheduling
PPT
Process management in os
OS Process Chapter 3.pdf
Presentation by adeel
Operating Systems CPU Scheduling and its Algorithms
Ch05 cpu-scheduling
Cpu scheduling
Scheduling Algorithms-Examples.pptx
Week 5a.pptx of cpu scheduling operating system class
Scheduling Algorithm in System Designing.pptx
CPU Scheduling Part-II.pdf
Operating systems - Processes Scheduling
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU Scheduling
Cpu scheduling
CPU scheduling
UNIPROCESS SCHEDULING.pptx
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
3Chapter Three- CPU Scheduling this is the best.pptx
CPU Scheduling
Process management in os
Ad

More from International Institute of Information Technology (I²IT) (20)

PPTX
Understanding Natural Language Processing
PPTX
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
PPTX
Writing Skills: Importance of Writing Skills
PPTX
Professional Communication | Introducing Oneself
PPTX
PPTX
What Is Jenkins? Features and How It Works
PPTX
Data Science, Big Data, Data Analytics
PPTX
PPTX
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
PPTX
Sentiment Analysis in Machine Learning
PPT
Importance of Theory of Computations
PPT
Java as Object Oriented Programming Language
PPTX
PPTX
Data Visualization - How to connect Microsoft Forms to Power BI
Understanding Natural Language Processing
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Writing Skills: Importance of Writing Skills
Professional Communication | Introducing Oneself
What Is Jenkins? Features and How It Works
Data Science, Big Data, Data Analytics
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Sentiment Analysis in Machine Learning
Importance of Theory of Computations
Java as Object Oriented Programming Language
Data Visualization - How to connect Microsoft Forms to Power BI

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
A Presentation on Artificial Intelligence
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Approach and Philosophy of On baking technology
PDF
Modernizing your data center with Dell and AMD
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
A Presentation on Artificial Intelligence
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Approach and Philosophy of On baking technology
Modernizing your data center with Dell and AMD
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Monthly Chronicles - July 2025
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx

Operating System Scheduling Algorithms

  • 2. HOPE FOUNDATION’S INTERNATIONAL INSTITUTE OF INFORMATION TECHNOLOGY, (I²IT) www.isquareit.edu.in +91 20 22933441 / 2
  • 3. Scheduling Algorithms • CPU scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated the CPU. • There are many different CPU scheduling algorithms. • First Come First Serve Scheduling (FCFS) • Shortest Job First Scheduling (SJF) • Round Robin Scheduling (RR) • Priority Based Scheduling Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 4. First Come First Serve Scheduling (FCFS) • By far the simplest CPU-scheduling algorithm is the first-come, first-served (FCFS) scheduling algorithm. • With this scheme, the process that requests the CPU first is allocated the CPU first. • The implementation of the FCFS policy is easily managed with a FIFO queue. • When a process enters the ready queue, its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue. • The running process is then removed from the queue. • FCFS is non preemptive i.e.Process continues to run till the burst cycle ends Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 5. FCFS Example Process Arrival Time Burst Time P1 0 7 P2 0 4 P3 0 2 P4 0 5 Arrival Time: When Process enters Ready Queue Burst Time: Time Required by the process for execution Average Waiting Time = (0+7+11+13)/4 = 7.75 Average Response Time = (0+7+11+13)/4 = 7.75 (Same as Average Waiting Time) Gnatt Chart : Horizontal bar chart developed by Henry Gantt, an American Engineering and social scientist in 1917 as a production control tool P1 P2 P3 P4 Response Time = Time taken by a particular process to begin executing on CPU – Time it enters in ready queue. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 6. • Order of Scheduling matters Process Arrival Time Burst Time P1 0 7 P2 0 4 P3 0 2 P4 0 5 P1P2 P3 P4 Average Waiting Time = (0+4+6+11)/4 = 5.25 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 7. Convoy Effect • All processes wait for the one big process to get off the CPU Process Arrival Time Burst Time P1 0 7 P2 0 4 P3 0 2 P4 0 5 P1 P2 P3 P4 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 8. FCFS - Advantages & Disadvantages • Advantages • Simple • Fair ( as long as no process hogs the CPU, every process will eventually run) • Disadvantages • Waiting time depends on arrival order • Short processes stuck waiting for long process to complete Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 9. Shortest Job First (SJF) • A different approach to CPU scheduling is the shortest-job-first (SJF) scheduling algorithm. • This algorithm associates with each process the length of the process's next CPU burst. • When the CPU is available, it is assigned to the process that has the smallest next CPU burst. • If the next CPU bursts of two processes are the same, FCFS scheduling is used to break the tie. • No preemption : the process continues to execute until its CPU burst completes • With preemption : the process may get preempted when a new process arrives Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 10. SJF ( without preemption) Average wait time = (7+3+1+0) / 4 = 2.75 Average Response Time = (Average wait time) Process Arrival Time Burst Time P1 0 7 P2 0 4 P3 0 2 P4 0 1 Schedule P1 P2 P3 P4 P4 P3 P2 P1 Arrival Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 11. SJF ( without preemption) Average Wait Time = (0+8+4+0)/4 = 3 Average Response Time = (Average Wait Time) Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 4 2 P4 7 1 P1 P4 P3 P2Schedule Arrival P1 P2 P3 P4 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 12. SJF – Advantages & Disadvantages • Advantages • Optimal : Minimum average wait time • Disadvantages • Not Practical : difficult to predict burst time (learning to predict future) • May starve long jobs Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 13. Round Robin (RR) • The round-robin (RR) scheduling algorithm is designed especially for timesharing systems. • It is similar to FCFS scheduling, but preemption is added to switch between processes. • A small unit of time, called a time quantum or time slice, is defined. A time quantum is generally from 10 to 100 milliseconds. • The ready queue is treated as a circular queue. The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum. • To implement RR scheduling, we keep the ready queue as a FIFO queue of processes. • New processes are added to the tail of the ready queue. The CPU scheduler picks the first process from the ready queue, sets a timer to interrupt after 1 time quantum, and dispatches the process. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 14. Round Robin Scheduling P1 P2 P3 P4 P1 P2 P4 P1 P2 P3 P4 P3 P4 P1 P4 P1 P2 P1 P2 P2 P4 P4 P1 P1 Process Arrival Time Burst Time P1 0 5 P2 0 4 P3 0 2 P4 0 3 Schedule FIFO Time Slice =2 Average Wait Time = (9+8+4+10)/4 =7.75 Average Response Time = (0+2+4+6)/4 =3 No of Context Switch = 7 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 15. Round Robin Scheduling P1 P2 P3 P4 P1 P1 P2 P3 P1 P2 P4 P1 P2 P2 P3 P3 P1 P1 P2 P2 P2 P4 P4 P1 P1 Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 3 2 P4 9 1 Schedule FIFO Arrival Average Waiting Time = (7+6+3+3)/4 = 4.75 Average Response Time = (0+2+3+3)/4 = 2 No of Context Switches = 6 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 16. Round Robin Scheduling Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 3 2 P4 9 1 P1 P2 P3 P4 P1 P1 P2 P1 P3 P2 P1 P3 P2 P1 P4 P2 P1 P2 P1 P3 P3 P2 P2 P1 P1 P3 P3 P2 P2 P1 P1 P4 P4 P1 P2 P1 P1 Schedule FIFO Arrival Average Waiting Time = (7+7+4+2)/4 = 5 Average Response Time = (0+1+2+2)/4 = 1.25 No of Context Switches = 11 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 17. Round Robin Scheduling (Larger Timeslice) Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 3 2 P4 9 1 P1 P2 P3 P4 P1 P2 P3 P1 P4 P3 P2 P2 P3 P2 P3 P3 P1 P3 P1 P3 P1 P3 P1 P1 P4 P4 P3 P4 P3 P3 Schedule FIFO Arrival Average Waiting Time = (5+3+9+3)/4 = 5 Average Response Time = (0+3+6+3)/4 = 3 No of Context Switches = 5 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 18. Duration of Timeslice • Duration of time slice is very critical. • It affects both response time as well as number of context switches. • A short quantum timeslice • Good, because processes need not wait long before they are scheduled • Bad, because context switch overhead increases • A long quantum timeslice • Bad, because processes no longer appear to execute concurrently • May degrade system performance • Timeslice is typically kept between 10ms to 100ms Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 19. Round Robin – Advantages & Disadvantages • Advantages • Fair – Each process gets a fair chance to run on CPU • Low average wait time • Faster response time • Disadvantages • Increased context switching – Context switches are overhead • High average wait time, when burst times have equal lengths Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 20. Shortest Remaining Time First (SRTF) • Preemptive SJF scheduling is sometimes called shortest- remaining-time-first scheduling. • In SRTF scheduling, if a new process arrives with a shorter burst time than remaining of current processes then schedule new process. • It further reduces the average waiting time and average response time. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 21. Shortest Remaining Time First (SRTF) Process Arrival Time Burst Time P1 0 7 P2 2 4 P3 4 2 P4 7 1 Schedule Arrival P1 P2 P1 P2 burst time is 4, P1 remaining burst time is 5 (Preempt P1) P3 burst time is 2, P2 remaining burst time is 2 (No Preemption) P3 P2 P3 P4 P1 Average Wait Time = (7+0+2+1)/4 = 2.5 Average Response Time = (0+0+2+1)/4 =0.75 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 22. Priority Based Scheduling • Each process is assigned a priority. • A priority is a number in a range (e.g 0 to 255) • A small number would mean high priority and larger number would mean low priority • Scheduling policy : Pick the process from the ready queue having the highest priority • Advantage: Provides relative importance to processes • Disadvantage: Could lead to starvation of low priority processes. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 23. Priority Based Scheduling P2 P1 P4 P3 0 3 24 26 Process Priority Burst Time P1 2 21 P2 1 3 P3 4 6 P4 3 2 Average Waiting Time = (0+3+24+26)/4 = 13.25 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 24. Priority Based Scheduling P2 P5 P1 P3 P4 Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 0 1 6 16 18 19 Average Waiting Time = (6+0+16+18+1) = 8.2 Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 25. Priority Based Scheduling • Priority scheduling can be either preemptive or non-preemptive. • When a process arrives at the ready queue, its priority is compared with the priority of the currently running process. • A preemptive priority scheduling algorithm will preempt the CPU if the priority of the newly arrived process is higher than the priority of the currently running process. • A non-preemptive priority scheduling algorithm will simply put the new process at the head of the ready queue. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 26. Priority Scheduling – Drawbacks • A major problem with priority scheduling algorithms is indefinite blocking, or starvation. • A process that is ready to run but waiting for the CPU can be considered blocked. • A priority scheduling algorithm can leave some low priority processes waiting indefinitely. • In a heavily loaded computer system, a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU. Generally, one of two things will happen. • Either the process will eventually be run (when the system is finally lightly loaded), or the computer system will eventually crash and lose all unfinished low-priority processes. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 27. Solution to Starvation - Ageing • A solution to the problem of indefinite blockage of low-priority processes is aging. • Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time. • For example, if priorities range from 127 (low) to 0 (high), we could increase the priority of a waiting process by 1 every 15 minutes. • Eventually, even a process with an initial priority of 127 would have the highest priority in the system and would be executed. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]
  • 28. THANK YOU !! For further information please contact Prof. Deptii Chaudhari Department of Computer Engineering Hope Foundation’s International Institute of Information Technology, I2IT Hinjawadi, Pune – 411 057 Phone - +91 20 22933441 www.isquareit.edu.in | [email protected] Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - [email protected]