SlideShare a Scribd company logo
CPU Scheduling
Chapter 3
1
Operating System
2
CPU Scheduling
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
• Algorithm Evaluation
Basic Concepts
• Maximum CPU utilization obtained with multiprogramming
• CPU–I/O Burst Cycle – Process execution consists of a cycle of
CPU execution and I/O wait.
• CPU burst distribution
3
CPU Scheduler
• Selects from among the processes in memory that are ready to
execute, and allocates the CPU to one of them.
• CPU scheduling decisions may take place when a process:
1.Switches from running to waiting state.
2.Switches from running to ready state.
3.Switches from waiting to ready.
4.Terminates.
• Scheduling under 1 and 4 is non-preemptive.
• All other scheduling is preemptive.
4
Dispatcher
• Dispatcher module gives control of the CPU to the process
selected by the short-term scheduler; this involves:
 switching context
 switching to user mode
 jumping to the proper location in the user program to
restart that program
• Dispatch latency – time it takes for the dispatcher to stop one
process and start another running.
5
Scheduling Algorithms
• Scheduling algorithms can be divided into two categories with
respect to how they deal with clock interrupts:
 Non-preemptive scheduling
 run to completion method.
 Once a process is in running state, it continues to execute
until it terminates or blocks itself to wait for some event.
 Simple and easy to implement
 Preemptive scheduling
 The strategy of allowing processes that is logically run able
to be temporarily suspended and be moved to the ready
state.
 Guarantees acceptable response time and fairness
6
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible
• Throughput – # of processes that complete their execution per
time unit
• Turnaround time – amount of time to execute a particular
process
• Waiting time – amount of time a process has been waiting in the
ready queue
• Response time – amount of time it takes from when a request
was submitted until the first response is produced.
7
Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time
8
First-Come, First-Served (FCFS) Scheduling
• Example: Process Burst Time
P1 24
P2 3
P3 3
• Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
• Waiting time for P1 = 0; P2 = 24; P3 = 27
• Average waiting time: (0 + 24 + 27)/3 = 17
9
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order
P2 , P3 , P1 .
• The Gantt chart for the schedule is:
• Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case.
• Convoy effect short process behind long process
10
11
Shortest-Job-First (SJR) Scheduling
• Associate with each process the length of its next CPU burst. Use
these lengths to schedule the process with the shortest time.
• Two schemes:
 Non-preemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst.
 Preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the Shortest-Remaining-
Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time for a given set of
processes.
12
Example of Non-Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
• SJF (non-preemptive)
• Average waiting time = (0 + 6 + 3 + 7)/4 = 4
13
FCFS Vs SJF
Process Burst Time
A 8
B 4
C 4
D 4
a) TAT = (8 + 12 + 16 + 20)/4 = 14
b) TAT = (4 + 8 + 12 + 20)/4 = 11
14
Round Robin (RR)
• Each process gets a small unit of CPU time (time quantum), usually
10-100 milliseconds. After this time has elapsed, the process is
preempted and added to the end of the ready queue.
• If there are n processes in the ready queue and the time quantum is
q, then each process gets 1/n of the CPU time in chunks of at most q
time units at once. No process waits more than (n-1)q time units.
• Performance
 q large FIFO
⇒
 q small ⇒ q must be large with respect to context switch,
otherwise overhead is too high.
15
Example: RR with Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
• The Gantt chart is:
• Typically, higher average turnaround than SJF, but better response.
16
How a Smaller Time Quantum Increases
Context Switches
17
Priority Scheduling
• A priority number (integer) is associated with each process
• The CPU is allocated to the process with the highest priority (smallest
integer ≡ highest priority).
 Preemptive
 Non-preemptive
• SJF is a priority scheduling where priority is the predicted next CPU
burst time.
• Problem ≡ Starvation – low priority processes may never execute.
• Solution ≡ Aging – as time progresses increase the priority of the
process.
18
Example of Priority Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
• Average waiting time = 8.2millisecond
19
Algorithm Evaluation
• Deterministic modeling – takes a particular predetermined workload
and defines the performance of each algorithm for that workload.
• Queuing models
• Implementation
20
Evaluation of CPU Schedulers by Simulation
Thank You ...

More Related Content

PDF
OS Process Chapter 3.pdf
Kp Sharma
 
PPTX
Cpu scheduling
mohsinalilarik1
 
PPT
Ch05 cpu-scheduling
Nazir Ahmed
 
PDF
ch5_CPU Scheduling_part1.pdf
SonaliAjankar
 
PPT
ch_scheduling (1).ppt
Farhanahmad540205
 
PPT
OS-operating systems- ch05 (CPU Scheduling) ...
Dr. Mazin Mohamed alkathiri
 
PPTX
CPU Scheduling Lecture 5 - 6.pptx
Harry83774
 
PDF
CPU Scheduling Part-III.pdf
Harika Pudugosula
 
OS Process Chapter 3.pdf
Kp Sharma
 
Cpu scheduling
mohsinalilarik1
 
Ch05 cpu-scheduling
Nazir Ahmed
 
ch5_CPU Scheduling_part1.pdf
SonaliAjankar
 
ch_scheduling (1).ppt
Farhanahmad540205
 
OS-operating systems- ch05 (CPU Scheduling) ...
Dr. Mazin Mohamed alkathiri
 
CPU Scheduling Lecture 5 - 6.pptx
Harry83774
 
CPU Scheduling Part-III.pdf
Harika Pudugosula
 

Similar to 3Chapter Three- CPU Scheduling this is the best.pptx (20)

PPT
CPU Scheduling Algorithms(FCFS,SJF,RR).ppt
2350482
 
PDF
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
baijusurya7
 
PPTX
CPU Scheduling.pptx this is operating system
harshinidh06
 
PPT
chapter 5 CPU scheduling.ppt
KeyreSebre
 
PPT
Cpu scheduling
Prakash Sir
 
PDF
5 Process Scheduling
Dr. Loganathan R
 
PPTX
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
Rajapriya82
 
PPT
operating system Scheduling process unit 3.ppt
ManoRanjani30
 
PPTX
Scheduling algorithms
Paurav Shah
 
PPTX
CPU Scheduling
sammerkhan1
 
PPTX
CPU Scheduling
M. Abdullah Wasif
 
PPTX
operating system scheduling concept lec2
thakurnishant1903200
 
PPTX
Operating Systems CPU Scheduling and its Algorithms
Sivakumar M
 
PPTX
DISEÑO DE MEMORIA EN SISTEMAS DE INFORMACION DIGITALES
2021207019est
 
PPT
scheduling Uni processor Long-term .ppt
Saba651353
 
PPT
OSCh6
Joe Christensen
 
CPU Scheduling Algorithms(FCFS,SJF,RR).ppt
2350482
 
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
baijusurya7
 
CPU Scheduling.pptx this is operating system
harshinidh06
 
chapter 5 CPU scheduling.ppt
KeyreSebre
 
Cpu scheduling
Prakash Sir
 
5 Process Scheduling
Dr. Loganathan R
 
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
Rajapriya82
 
operating system Scheduling process unit 3.ppt
ManoRanjani30
 
Scheduling algorithms
Paurav Shah
 
CPU Scheduling
sammerkhan1
 
CPU Scheduling
M. Abdullah Wasif
 
operating system scheduling concept lec2
thakurnishant1903200
 
Operating Systems CPU Scheduling and its Algorithms
Sivakumar M
 
DISEÑO DE MEMORIA EN SISTEMAS DE INFORMACION DIGITALES
2021207019est
 
scheduling Uni processor Long-term .ppt
Saba651353
 
Ad

Recently uploaded (20)

PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
CDH. pptx
AneetaSharma15
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
Ad

3Chapter Three- CPU Scheduling this is the best.pptx

  • 2. 2 CPU Scheduling • Basic Concepts • Scheduling Criteria • Scheduling Algorithms • Algorithm Evaluation
  • 3. Basic Concepts • Maximum CPU utilization obtained with multiprogramming • CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait. • CPU burst distribution 3
  • 4. CPU Scheduler • Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. • CPU scheduling decisions may take place when a process: 1.Switches from running to waiting state. 2.Switches from running to ready state. 3.Switches from waiting to ready. 4.Terminates. • Scheduling under 1 and 4 is non-preemptive. • All other scheduling is preemptive. 4
  • 5. Dispatcher • Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:  switching context  switching to user mode  jumping to the proper location in the user program to restart that program • Dispatch latency – time it takes for the dispatcher to stop one process and start another running. 5
  • 6. Scheduling Algorithms • Scheduling algorithms can be divided into two categories with respect to how they deal with clock interrupts:  Non-preemptive scheduling  run to completion method.  Once a process is in running state, it continues to execute until it terminates or blocks itself to wait for some event.  Simple and easy to implement  Preemptive scheduling  The strategy of allowing processes that is logically run able to be temporarily suspended and be moved to the ready state.  Guarantees acceptable response time and fairness 6
  • 7. Scheduling Criteria • CPU utilization – keep the CPU as busy as possible • Throughput – # of processes that complete their execution per time unit • Turnaround time – amount of time to execute a particular process • Waiting time – amount of time a process has been waiting in the ready queue • Response time – amount of time it takes from when a request was submitted until the first response is produced. 7
  • 8. Optimization Criteria • Max CPU utilization • Max throughput • Min turnaround time • Min waiting time • Min response time 8
  • 9. First-Come, First-Served (FCFS) Scheduling • Example: Process Burst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17 9
  • 10. FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P2 , P3 , P1 . • The Gantt chart for the schedule is: • Waiting time for P1 = 6; P2 = 0; P3 = 3 • Average waiting time: (6 + 0 + 3)/3 = 3 • Much better than previous case. • Convoy effect short process behind long process 10
  • 11. 11 Shortest-Job-First (SJR) Scheduling • Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. • Two schemes:  Non-preemptive – once CPU given to the process it cannot be preempted until completes its CPU burst.  Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining- Time-First (SRTF). • SJF is optimal – gives minimum average waiting time for a given set of processes.
  • 12. 12 Example of Non-Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (non-preemptive) • Average waiting time = (0 + 6 + 3 + 7)/4 = 4
  • 13. 13 FCFS Vs SJF Process Burst Time A 8 B 4 C 4 D 4 a) TAT = (8 + 12 + 16 + 20)/4 = 14 b) TAT = (4 + 8 + 12 + 20)/4 = 11
  • 14. 14 Round Robin (RR) • Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. • If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. • Performance  q large FIFO ⇒  q small ⇒ q must be large with respect to context switch, otherwise overhead is too high.
  • 15. 15 Example: RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 • The Gantt chart is: • Typically, higher average turnaround than SJF, but better response.
  • 16. 16 How a Smaller Time Quantum Increases Context Switches
  • 17. 17 Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority).  Preemptive  Non-preemptive • SJF is a priority scheduling where priority is the predicted next CPU burst time. • Problem ≡ Starvation – low priority processes may never execute. • Solution ≡ Aging – as time progresses increase the priority of the process.
  • 18. 18 Example of Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 • Average waiting time = 8.2millisecond
  • 19. 19 Algorithm Evaluation • Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm for that workload. • Queuing models • Implementation
  • 20. 20 Evaluation of CPU Schedulers by Simulation