SlideShare a Scribd company logo
1 of 21
Download to read offline
Chapter 5: CPU Scheduling
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 followed by I/O
burst
• CPU burst distribution is of
main concern
Histogram of CPU-burst Times
Large number of short bursts
Small number of longer bursts
CPU Scheduler
• The CPU scheduler selects from among the
processes in ready queue, and allocates a CPU
core to one of them
• Queue may be ordered in various ways
• 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
Preemptive and Nonpreemptive Scheduling
• When scheduling takes place only under
circumstances 1 and 4, the scheduling scheme
is nonpreemptive.
• Otherwise, it is preemptive.
• Under Nonpreemptive scheduling, once the
CPU has been allocated to a process, the
process keeps the CPU until it releases it either
by terminating or by switching to the waiting
state.
• Virtually all modern operating systems including
Windows, MacOS, Linux, and UNIX use
preemptive scheduling algorithms.
Preemptive Scheduling and Race Conditions
• Preemptive scheduling can result in race
conditions when data are shared among
several processes.
• Consider the case of two processes that
share data. While one process is updating
the data, it is preempted so that the second
process can run. The second process then
tries to read the data, which are in an
inconsistent state.
• This issue will be explored in detail in
Chapter 6.
Dispatcher
• Dispatcher module gives control
of the CPU to the process
selected by the CPU 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
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.
SchedulingAlgorithm Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time
First- Come, First-Served (FCFS) Scheduling
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
P P P
1 2 3
0 24 30
27
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
• Consider one CPU-bound and many I/O-bound processes
P1
0 3 6 30
P2
P3
Shortest-Job-First (SJF) Scheduling
• Associate with each process the length of its
next CPU burst
• Use these lengths to schedule the process with the
shortest time
• SJF is optimal – gives minimum average
waiting time for a given set of processes
• Preemptive version called shortest-
remaining-time-first
• How do we determine the length of the next
CPU burst?
• Could ask the user
• Estimate
Example of SJF
Process Burst Time
P1 6
P2 8
P3 7
P4 3
• SJF scheduling chart
• Average waiting time =
(3 + 16 + 9 + 0) / 4 = 7
P3
0 3 24
P4
P1
16
9
P2
Example of SJF
• Nonpreemptive policy
Example of SJF
• Nonpreemptive policy
Determining Length of Next CPU Burst
• Can only estimate the length – should be similar to
the previous one
• Then pick process with shortest predicted next CPU burst
• Can be done by using the length of previous CPU
bursts, using exponential averaging
• Commonly, α set to ½
Examples of Exponential Averaging
•  =0
• n+1 = n
• Recent history does not count
•  =1
• n+1 =  tn
• Only the actual last CPU burst counts
• If we expand the formula, we get:
n+1 =  tn+(1 - ) tn -1 + …
+(1 -  )j  tn -j + …
+(1 -  )n +1 0
• Since both  and (1 - ) are less than or equal to 1,
each successor predecessor term has less weight
than its predecessor
Exponential Averaging
• A common technique for predicting a future value on the
basis of a time series of past values is exponential
averaging
• Given  =0.8,
Shortest Remaining Time First Scheduling
• Preemptive version of SJN
• Whenever a new process arrives in the ready
queue, the decision on which process to
schedule next is redone using the SJN
algorithm.
• Is SRT more “optimal” than SJN in terms of the
minimum average waiting time for a given set
of processes?
Example of Shortest-remaining-time-first
• Now we add the concepts of varying arrival times and
preemption to the analysis
Process i Arrival TimeTBurst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
• Preemptive SJF Gantt Chart
• Average waiting time =
• [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5
P4
0 1 26
P1
P2
10
P3
P1
5 17
Example of Shortest-remaining-time-first

More Related Content

Similar to ch5_CPU Scheduling_part1.pdf

CPU Scheduling Lecture 5 - 6.pptx
CPU Scheduling Lecture 5 - 6.pptxCPU Scheduling Lecture 5 - 6.pptx
CPU Scheduling Lecture 5 - 6.pptxHarry83774
 
operating system (1).pdf
operating system (1).pdfoperating system (1).pdf
operating system (1).pdfAliyanAbbas1
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithmsPaurav Shah
 
Operating system 29 non preemptive scheduling
Operating system 29 non preemptive schedulingOperating system 29 non preemptive scheduling
Operating system 29 non preemptive schedulingVaibhav Khanna
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCKVicky Kumar
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.pptKeyreSebre
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithmssathish sak
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptxjamilaltiti1
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithmBinal Parekh
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingVaibhav Khanna
 
Ch6
Ch6Ch6
Ch6C.U
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling gopi7
 
CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptxyashu23
 

Similar to ch5_CPU Scheduling_part1.pdf (20)

CPU Scheduling Lecture 5 - 6.pptx
CPU Scheduling Lecture 5 - 6.pptxCPU Scheduling Lecture 5 - 6.pptx
CPU Scheduling Lecture 5 - 6.pptx
 
operating system (1).pdf
operating system (1).pdfoperating system (1).pdf
operating system (1).pdf
 
Presentation by adeel
Presentation by adeelPresentation by adeel
Presentation by adeel
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Operating system 29 non preemptive scheduling
Operating system 29 non preemptive schedulingOperating system 29 non preemptive scheduling
Operating system 29 non preemptive scheduling
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCK
 
CPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdfCPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdf
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
Ch5
Ch5Ch5
Ch5
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of scheduling
 
Ch6
Ch6Ch6
Ch6
 
Ch05
Ch05Ch05
Ch05
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptx
 
OSCh6
OSCh6OSCh6
OSCh6
 

More from SonaliAjankar

More from SonaliAjankar (7)

page replacement algorithms.pdf
page replacement algorithms.pdfpage replacement algorithms.pdf
page replacement algorithms.pdf
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
assem.ppt
assem.pptassem.ppt
assem.ppt
 
part2.pdf
part2.pdfpart2.pdf
part2.pdf
 
l1.ppt
l1.pptl1.ppt
l1.ppt
 
Unit 5 Streams2.pptx
Unit 5 Streams2.pptxUnit 5 Streams2.pptx
Unit 5 Streams2.pptx
 
Mobile transport layer
 Mobile transport layer Mobile transport layer
Mobile transport layer
 

Recently uploaded

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 

Recently uploaded (20)

young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

ch5_CPU Scheduling_part1.pdf

  • 1. Chapter 5: CPU Scheduling
  • 2. 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 followed by I/O burst • CPU burst distribution is of main concern
  • 3. Histogram of CPU-burst Times Large number of short bursts Small number of longer bursts
  • 4. CPU Scheduler • The CPU scheduler selects from among the processes in ready queue, and allocates a CPU core to one of them • Queue may be ordered in various ways • 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
  • 5. Preemptive and Nonpreemptive Scheduling • When scheduling takes place only under circumstances 1 and 4, the scheduling scheme is nonpreemptive. • Otherwise, it is preemptive. • Under Nonpreemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases it either by terminating or by switching to the waiting state. • Virtually all modern operating systems including Windows, MacOS, Linux, and UNIX use preemptive scheduling algorithms.
  • 6. Preemptive Scheduling and Race Conditions • Preemptive scheduling can result in race conditions when data are shared among several processes. • Consider the case of two processes that share data. While one process is updating the data, it is preempted so that the second process can run. The second process then tries to read the data, which are in an inconsistent state. • This issue will be explored in detail in Chapter 6.
  • 7. Dispatcher • Dispatcher module gives control of the CPU to the process selected by the CPU 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
  • 8. 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.
  • 9. SchedulingAlgorithm Optimization Criteria • Max CPU utilization • Max throughput • Min turnaround time • Min waiting time • Min response time
  • 10. First- Come, First-Served (FCFS) Scheduling 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 P P P 1 2 3 0 24 30 27
  • 11. 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 • Consider one CPU-bound and many I/O-bound processes P1 0 3 6 30 P2 P3
  • 12. Shortest-Job-First (SJF) Scheduling • Associate with each process the length of its next CPU burst • Use these lengths to schedule the process with the shortest time • SJF is optimal – gives minimum average waiting time for a given set of processes • Preemptive version called shortest- remaining-time-first • How do we determine the length of the next CPU burst? • Could ask the user • Estimate
  • 13. Example of SJF Process Burst Time P1 6 P2 8 P3 7 P4 3 • SJF scheduling chart • Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P3 0 3 24 P4 P1 16 9 P2
  • 14. Example of SJF • Nonpreemptive policy
  • 15. Example of SJF • Nonpreemptive policy
  • 16. Determining Length of Next CPU Burst • Can only estimate the length – should be similar to the previous one • Then pick process with shortest predicted next CPU burst • Can be done by using the length of previous CPU bursts, using exponential averaging • Commonly, α set to ½
  • 17. Examples of Exponential Averaging •  =0 • n+1 = n • Recent history does not count •  =1 • n+1 =  tn • Only the actual last CPU burst counts • If we expand the formula, we get: n+1 =  tn+(1 - ) tn -1 + … +(1 -  )j  tn -j + … +(1 -  )n +1 0 • Since both  and (1 - ) are less than or equal to 1, each successor predecessor term has less weight than its predecessor
  • 18. Exponential Averaging • A common technique for predicting a future value on the basis of a time series of past values is exponential averaging • Given  =0.8,
  • 19. Shortest Remaining Time First Scheduling • Preemptive version of SJN • Whenever a new process arrives in the ready queue, the decision on which process to schedule next is redone using the SJN algorithm. • Is SRT more “optimal” than SJN in terms of the minimum average waiting time for a given set of processes?
  • 20. Example of Shortest-remaining-time-first • Now we add the concepts of varying arrival times and preemption to the analysis Process i Arrival TimeTBurst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5 • Preemptive SJF Gantt Chart • Average waiting time = • [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5 P4 0 1 26 P1 P2 10 P3 P1 5 17