SlideShare une entreprise Scribd logo
1  sur  18
ِ‫ن‬ ٰ‫م‬ْ‫ح‬َّ‫الر‬ ِ‫هللا‬ ِ‫م‬ْ‫س‬ِ‫ب‬ِ‫ْم‬‫ي‬ ِ‫ح‬َّ‫الر‬
GROUP MEMBERS
2611
2625
2608
2609
1. Muhammad Waqas
4. Waqar Iqbal
2. Sheroz Aftab
5. Shahzaib Ali
3. Hammad Ali
2645
Topi
c
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 distribution
ALTERNATING SEQUENCE OF CPU AND I/O BURSTS
Load store
Add store
Read from file
Store increment
index write to
file
Load store
Add store
Read from file
Wait for I/O
Cpu burst
I/O burst
Cpu
burst
Wait for I/O I/O burst
Cpu
burst
Wait for I/O I/O burst
Histogram of CPU-burst Times
CPU SCHEDULER
 Selects from among the processes in ready queue, and allocates the CPU 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
Scheduling under 1 and 4 is non-preemptive
All other scheduling is preemptive
 Consider access to shared data
Consider preemption while in kernel mode
Consider interrupts occurring during crucial OS activities
DISPATCHER
Scheduler: selects one process to run on CPU
Dispatcher: allocates CPU to the selected process, which involves:
1. Switching context
2. switching to user mode
3. jumping to the proper location (in the selected process) and restarting it
Dispatcher should be fast enough.
 Dispatch latency – time it takes for the dispatcher to stop one process and start
another running.
Types of Scheduler
1. Non-preemptive
2. Preemptive
Non-preemptive
• Once a process is allocated the CPU, it does not leave unless:
1. it has to wait, e.g., for I/O request or for a child to terminate
2. it terminates
Preemptive
OS can force (preempt) a process from CPU at anytime
Say, to allocate CPU to another higher-priority process
SCHEDULING CRITERIA
CPU utilization – keep the CPU as busy as possible
• Maximize
Throughput – No of processes that complete their execution per time unit
• Maximize
Turnaround time – amount of time to execute a particular process (time from submission to termination) i.e
(waiting in memory + waiting time in ready queue + executing time in CPU + doing IO)
• Minimize
Waiting time – amount of time a process has been waiting in the ready queue (sum of time waiting in ready
queue)
• Minimize
Response time – amount of time it takes from when a request was submitted until the first response is
produced, not output (for time-sharing environment)
• Minimize
TYPES OF SCHEDULING ALGORITHM
1. First Come, First Served (FCFS)
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
Process Burst
Time
P1 24
P2 3
P3 3
P1 P2 P3
0 24 27
30
 Suppose that the processes arrive in the order : P2 , P3 , P1
(P1:24,P2:3,P3:3)
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
P2 P3 P1
0 3 6
30
2. SHORTEST-JOB-FIRST SCHEDULING
Associate with each process the length of its next CP 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
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
P1 P3 P2 P4
0 3 7 8 12 16
Example of Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
SJF (preemptive)
Average waiting time = (9 + 1 + 0 +2)/4 - 3
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
3. 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 priority scheduling where priority is the inverse of predicted next
CPU burst time
Problem ≡ Starvation – low priority processes may never execute
Solution ≡ Aging – as time progresses increase the priority of the
process
EXAMPLE OF PRIORITY SCHEDULING
Example of Non-Preemptive SJF
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Priority scheduling Gantt Chart
Average waiting time = 8.2 M - sec
P1 P3 P2 P4
0 1 6 16 18 19
4. ROUND-ROBIN SCHEDULING
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
EXAMPLE OF ROUND-ROBIN SCHEDULING
Process Burst
Time
P1 24
P2 3
P3 3
 Quantum time 4millisec
The Gantt chart is:
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26
30
 Typically, higher average turnaround than SJF, but better
response
Thank You
Any Questions
??

Contenu connexe

Tendances (20)

Algorithm o.s.
Algorithm o.s.Algorithm o.s.
Algorithm o.s.
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Process and CPU scheduler
Process and CPU schedulerProcess and CPU scheduler
Process and CPU scheduler
 
PPT CPU
PPT CPUPPT CPU
PPT CPU
 
CPU Sheduling
CPU Sheduling CPU Sheduling
CPU Sheduling
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Ch05
Ch05Ch05
Ch05
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 
Chapter6
Chapter6Chapter6
Chapter6
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Priority scheduling algorithms
Priority scheduling algorithmsPriority scheduling algorithms
Priority scheduling algorithms
 
cpu scheduling OS
 cpu scheduling OS cpu scheduling OS
cpu scheduling OS
 
Chapter4
Chapter4Chapter4
Chapter4
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
 

Similaire à CPU Scheduling

Similaire à CPU Scheduling (20)

Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
CPU Scheduling.pdf
CPU Scheduling.pdfCPU Scheduling.pdf
CPU Scheduling.pdf
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
 
ch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdfch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdf
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Ch5
Ch5Ch5
Ch5
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
OSCh6
OSCh6OSCh6
OSCh6
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
 
Cpu_sheduling.pptx
Cpu_sheduling.pptxCpu_sheduling.pptx
Cpu_sheduling.pptx
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 

Dernier

Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdfHafizMudaserAhmad
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdfAkritiPradhan2
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodManicka Mamallan Andavar
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfalene1
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 
signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsapna80328
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESkarthi keyan
 
OOP concepts -in-Python programming language
OOP concepts -in-Python programming languageOOP concepts -in-Python programming language
OOP concepts -in-Python programming languageSmritiSharma901052
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书rnrncn29
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSsandhya757531
 
List of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdfList of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdfisabel213075
 

Dernier (20)

Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument method
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 
signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveying
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
 
OOP concepts -in-Python programming language
OOP concepts -in-Python programming languageOOP concepts -in-Python programming language
OOP concepts -in-Python programming language
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
 
List of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdfList of Accredited Concrete Batching Plant.pdf
List of Accredited Concrete Batching Plant.pdf
 

CPU Scheduling

  • 1. ِ‫ن‬ ٰ‫م‬ْ‫ح‬َّ‫الر‬ ِ‫هللا‬ ِ‫م‬ْ‫س‬ِ‫ب‬ِ‫ْم‬‫ي‬ ِ‫ح‬َّ‫الر‬
  • 2. GROUP MEMBERS 2611 2625 2608 2609 1. Muhammad Waqas 4. Waqar Iqbal 2. Sheroz Aftab 5. Shahzaib Ali 3. Hammad Ali 2645
  • 3. Topi c 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 distribution
  • 4. ALTERNATING SEQUENCE OF CPU AND I/O BURSTS Load store Add store Read from file Store increment index write to file Load store Add store Read from file Wait for I/O Cpu burst I/O burst Cpu burst Wait for I/O I/O burst Cpu burst Wait for I/O I/O burst Histogram of CPU-burst Times
  • 5. CPU SCHEDULER  Selects from among the processes in ready queue, and allocates the CPU 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 Scheduling under 1 and 4 is non-preemptive All other scheduling is preemptive  Consider access to shared data Consider preemption while in kernel mode Consider interrupts occurring during crucial OS activities
  • 6. DISPATCHER Scheduler: selects one process to run on CPU Dispatcher: allocates CPU to the selected process, which involves: 1. Switching context 2. switching to user mode 3. jumping to the proper location (in the selected process) and restarting it Dispatcher should be fast enough.  Dispatch latency – time it takes for the dispatcher to stop one process and start another running. Types of Scheduler 1. Non-preemptive 2. Preemptive
  • 7. Non-preemptive • Once a process is allocated the CPU, it does not leave unless: 1. it has to wait, e.g., for I/O request or for a child to terminate 2. it terminates Preemptive OS can force (preempt) a process from CPU at anytime Say, to allocate CPU to another higher-priority process
  • 8. SCHEDULING CRITERIA CPU utilization – keep the CPU as busy as possible • Maximize Throughput – No of processes that complete their execution per time unit • Maximize Turnaround time – amount of time to execute a particular process (time from submission to termination) i.e (waiting in memory + waiting time in ready queue + executing time in CPU + doing IO) • Minimize Waiting time – amount of time a process has been waiting in the ready queue (sum of time waiting in ready queue) • Minimize Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) • Minimize
  • 9. TYPES OF SCHEDULING ALGORITHM 1. First Come, First Served (FCFS) 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 Process Burst Time P1 24 P2 3 P3 3 P1 P2 P3 0 24 27 30
  • 10.  Suppose that the processes arrive in the order : P2 , P3 , P1 (P1:24,P2:3,P3:3) 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 P2 P3 P1 0 3 6 30
  • 11. 2. SHORTEST-JOB-FIRST SCHEDULING Associate with each process the length of its next CP 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 P1 P3 P2 P4 0 3 7 8 12 16
  • 13. Example of Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (preemptive) Average waiting time = (9 + 1 + 0 +2)/4 - 3 P1 P2 P3 P2 P4 P1 0 2 4 5 7 11 16
  • 14. 3. 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 priority scheduling where priority is the inverse of predicted next CPU burst time Problem ≡ Starvation – low priority processes may never execute Solution ≡ Aging – as time progresses increase the priority of the process
  • 15. EXAMPLE OF PRIORITY SCHEDULING Example of Non-Preemptive SJF Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 Priority scheduling Gantt Chart Average waiting time = 8.2 M - sec P1 P3 P2 P4 0 1 6 16 18 19
  • 16. 4. ROUND-ROBIN SCHEDULING 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
  • 17. EXAMPLE OF ROUND-ROBIN SCHEDULING Process Burst Time P1 24 P2 3 P3 3  Quantum time 4millisec The Gantt chart is: P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30  Typically, higher average turnaround than SJF, but better response