SlideShare una empresa de Scribd logo
1 de 31
CPU scheduling
Mohd Amir khan
CPU scheduling
 A process execution consist office cycle of CPU execution and input output
execution
 Every process begins with CPU burst that may be followed by input output
bus, then another CPU burst and then input output burst and so on
eventually in the last will end up on CPU burst
 CPU burst there are those processes which require most of time on CPU
 Input output bus which require most of the time on input output devices
for peripherals
 A good CPU scheduling idea should choose the mixture of both so that
both input and output devices and CPU can be utilized efficiently
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
For example
o cricket team
o printing document
o addition of two numbers
CPU scheduling terminology
 Burst time /execution time /running time:- is the time causes required for
running on CPU
 Waiting time:- time spent by a process in ready state waiting for CPU
 Arrival time:- When a process enters ready state
 Turnaround time:- total time spent by a process in the system and around time
equal to {exit time - arrival time} or {burst time + waiting time}
 Response time:- Time between a process enters ready queue and get
scheduled on the CPU for the first time
 Exit time:- when process completes execution and exit from system
Histogram of CPU-burst Times
CPU scheduling Algorithm
 Two approaches
1. Non-Preemptive Scheduling:
2. Preemptive Scheduling:
 Non-preemptive
 Once resources(CPU Cycle) are allocated to a process, the process holds it till it completes its burst time or switches
to waiting state
 Process can not be interrupted until it terminates itself or its time is up.
 Rigid, not cost association
 Preemptive
 In this resources(CPU Cycle) are allocated to a process for a limited time
 Process can be interrupted in between.
 Flexible and cost associated
Scheduling Algorithm Optimization Criteria
 Max CPU utilization
 Max throughput
 Min turnaround time
 Min waiting time
 Min response time
First Come First serve (FCFS)
 It assign CPU to the process which arrives first
 Easy to understand and can easily be implemented using queue data structure
 Allows non-pre-emptive in nature
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 P1 2 3
0 24 3027
A Gantt chart is a horizontal bar chart
developed as a production control tool in
1917 by Henry L. Gantt,
an American engineer and social scientist
Solve this
Pid AT BT TAT WT
A 3 4
B 5 3
C 0 2
D 5 1
E 4 3
Create Gantt Chart
Calculate Waiting Time of each and
average waiting time
Convoy Effect
Pid AT BT WT AWT
P1 0 100 0
P2 1 1 99
Create Gantt Chart
Pid AT BT WT AWT
P1 1 100 1
P2 0 1 0
Create Gantt Chart
Smaller process have to wait for long time for bigger process to release CPU
Advantages
 Easy to learn
 Easy to understand
 Easy to implement
 We used for background process where execution is not urgent
Disadvantages
 Suffer from Convoy effect
 Normally long average waiting time
 No consideration to burst time or arrival time/Priority
 Should not be used for interactive system
Shortest job first (non-preemptive) shortest
remaining time first(SRTF) (preemptive)
 Out of all available process CPU is assigned to the process having smallest burst time
requirement no priority, no seniority
 If there is tie first Come First serve is used to break tie
 Can we used both with non primitive and primitive approach
 Primitive version STRF is also called as optimal as it currently minimum average waiting
time
Example of SJF
Process Arrivall Time Burst Time
P1 1 6
P2 2 8
P3 4 7
P4 0 3
 SJF scheduling chart
 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
P3
0 3 24
P4
P1
169
P2
SJF (non-preemptive)
Pid AT BT TAT WT
A 3 1
B 1 4
C 4 2
D 0 6
E 2 3
Create Gantt Chart
Calculate Waiting Time of Processes
Example of Shortest-remaining-time-first
 Now we add the concepts of varying arrival times and preemption to
the analysis
Process Arrival Time Burst 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
SRTF(Pre-emptive)
Pid AT BT TAT WT
A 3 4
B 5 3
C 0 2
D 5 1
E 4 3
Create Gantt Chart
Calculate Waiting Time of Processes
Advantages and disadvantages of shortest job
first scheduling algorithm
Advantages
 SRTF guarantees minimal average waiting
time
 Standard for other algorithm in terms of
average waiting time
 Better Average response time compare to
First Come First serve
Disadvantages
 Algorithm cannot be implemented as there
is no way to know the burst time of a
process
 Process with the longest CPU burst time
requirement will go into starvation
 No idea of priority, process with large burst
time have work response time
Priority Algorithm
 Here a priority is associated with each process
 At any instance of time out of all available process, CPU is allocated to the process
which posses the highest Priority
 Tie is broken with FCFS order
 No importance to arrival time or burst time
 Supports both non pre-emptive and pre-emptive version
Continue..
 A priority number (integer) is associated with each process
 The CPU is allocated to the process with the 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(Non-preemptive)
Process Arrival Time Burst Time Priority
P1 1 10 5
P2 0 1 3
P3 2 2 5
P4 3 1 4
P5 1 5 7
Priority scheduling Gantt Chart
 Average waiting time
Non Pre-emptive
Pid AT BT Priority TAT WT
P1 0 4 2
P2 1 3 3
P3 2 1 4
P4 3 5 5
P5 4 2 5
Create Gantt Chart
Calculate Waiting Time of Processes
Pre-emptive
Pid AT BT Priority TAT WT
P1 0 4 2
P2 1 3 3
P3 2 1 4
P4 3 5 5
P5 4 2 5
Create Gantt Chart
Calculate Waiting Time of Processes
Advantages and disadvantages of priority
scheduling algorithm
Advantages
 Provide a facility of priority specially for
system process
 Allows to run important process first even
if it is a user process
Disadvantages
 Here process with smaller priority may
starve for CPU
 No idea of response time or waiting time
 Note aging is a technique of gradually
increasing the priority of process that wait
in the system for long time
Round Robin (RR)
 Each process gets a small unit of CPU time (time quantum q),
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.
 Timer interrupts every quantum to schedule next process
 Performance
 q large  FIFO
 q small  q must be large with respect to context switch, otherwise
overhead is too high
Continue.
 It is design for time sharing system where it is not necessary to complete one process
and then start another, but to be responsive and divide time of CPU among the
process in the ready state
 Here ready q to be treated as circular queue
 We will fix the time quantum up to which process can hold the CPU in one go within
which either a process terminates or process must release the CPU and re-enter in the
circular queue and wait for the next chance
 Round Robin is called preemptive in nature
Example of RR with Time Quantum =
4
Process Burst Time
P1 24
P2 3
P3 3
 The Gantt chart is:
 Typically, higher average turnaround than SJF, but better response
 q should be large compared to context switch time
 q usually 10ms to 100ms, context switch < 10 usec
P P P1 1 1
0 18 3026144 7 10 22
P2
P3
P1
P1
P1
Pre-emptive
Pid AT BT TAT WT
A 0 5
B 1 3
C 2 1
D 3 2
E 4 3
TQ=2
Create Queue
Create Gantt Chart
Calculate Waiting Time of Processes
Advantages and disadvantages of Round Robin
scheduling algorithm
 Advantages
 Perform best in terms of average response
time
 Works well in call to time sharing system,
client server architecture and interactive
system
 Kind of shortest job first implementation
 Disadvantages
 Longer process may starve
 Performance depends heavily on time
Quantum
 No idea of reality
1. The following is the set of processes whose arrival time, burst time and the priorities are given
below:
S.No. Process Arrival time (in ms) Bunt Time(in ms) Priority
1 P1 0 10 5
2 P2 0 5 2
3 P3 2 3 1
4 P4 5 20 4
5 P5 10 2 3
If Shortest job first ( vith pre-emption) scheduling policy and Priority scheduling policy(with pre-
emption) is used then, what will be the average waiting time in both the cases?
Ops:
A. 5.6 ms, 8 ms
B. None of the mentioned options
C. 6.8 ms, 7.6 ms
D. 0 5.6 ms, 7.6 ms
Question

Más contenido relacionado

La actualidad más candente

CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Mukesh Chinta
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithmsShanu Kumar
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process ConceptsMukesh Chinta
 
Module 3-cpu-scheduling
Module 3-cpu-schedulingModule 3-cpu-scheduling
Module 3-cpu-schedulingHesham Elmasry
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.pptKeyreSebre
 
Operating system 31 multiple processor scheduling
Operating system 31 multiple processor schedulingOperating system 31 multiple processor scheduling
Operating system 31 multiple processor schedulingVaibhav Khanna
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos conceptsanishgoel
 
Operating system architecture
Operating system architectureOperating system architecture
Operating system architectureSabin dumre
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First ServeEdwin Makeu
 

La actualidad más candente (20)

CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Cs8493 unit 3
Cs8493 unit 3Cs8493 unit 3
Cs8493 unit 3
 
Module 3-cpu-scheduling
Module 3-cpu-schedulingModule 3-cpu-scheduling
Module 3-cpu-scheduling
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
RTOS - Real Time Operating Systems
RTOS - Real Time Operating SystemsRTOS - Real Time Operating Systems
RTOS - Real Time Operating Systems
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
Operating system 31 multiple processor scheduling
Operating system 31 multiple processor schedulingOperating system 31 multiple processor scheduling
Operating system 31 multiple processor scheduling
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
Operating system architecture
Operating system architectureOperating system architecture
Operating system architecture
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 

Similar a CPU scheduling (20)

Process management in os
Process management in osProcess management in os
Process management in os
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
CH06.pdf
CH06.pdfCH06.pdf
CH06.pdf
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
OSCh6
OSCh6OSCh6
OSCh6
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
CPU Scheduling.pdf
CPU Scheduling.pdfCPU Scheduling.pdf
CPU Scheduling.pdf
 
Ch5
Ch5Ch5
Ch5
 
Ch6
Ch6Ch6
Ch6
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Os..
Os..Os..
Os..
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronization
 
Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 

Último

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
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
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
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
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
 
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
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 

Último (20)

POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
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
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
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
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
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
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
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
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
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
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 

CPU scheduling

  • 2. CPU scheduling  A process execution consist office cycle of CPU execution and input output execution  Every process begins with CPU burst that may be followed by input output bus, then another CPU burst and then input output burst and so on eventually in the last will end up on CPU burst  CPU burst there are those processes which require most of time on CPU  Input output bus which require most of the time on input output devices for peripherals  A good CPU scheduling idea should choose the mixture of both so that both input and output devices and CPU can be utilized efficiently
  • 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 followed by I/O burst  CPU burst distribution is of main concern For example o cricket team o printing document o addition of two numbers
  • 4. CPU scheduling terminology  Burst time /execution time /running time:- is the time causes required for running on CPU  Waiting time:- time spent by a process in ready state waiting for CPU  Arrival time:- When a process enters ready state  Turnaround time:- total time spent by a process in the system and around time equal to {exit time - arrival time} or {burst time + waiting time}  Response time:- Time between a process enters ready queue and get scheduled on the CPU for the first time  Exit time:- when process completes execution and exit from system
  • 6. CPU scheduling Algorithm  Two approaches 1. Non-Preemptive Scheduling: 2. Preemptive Scheduling:  Non-preemptive  Once resources(CPU Cycle) are allocated to a process, the process holds it till it completes its burst time or switches to waiting state  Process can not be interrupted until it terminates itself or its time is up.  Rigid, not cost association  Preemptive  In this resources(CPU Cycle) are allocated to a process for a limited time  Process can be interrupted in between.  Flexible and cost associated
  • 7. Scheduling Algorithm Optimization Criteria  Max CPU utilization  Max throughput  Min turnaround time  Min waiting time  Min response time
  • 8. First Come First serve (FCFS)  It assign CPU to the process which arrives first  Easy to understand and can easily be implemented using queue data structure  Allows non-pre-emptive in nature
  • 9. 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 P1 2 3 0 24 3027 A Gantt chart is a horizontal bar chart developed as a production control tool in 1917 by Henry L. Gantt, an American engineer and social scientist
  • 10. Solve this Pid AT BT TAT WT A 3 4 B 5 3 C 0 2 D 5 1 E 4 3 Create Gantt Chart Calculate Waiting Time of each and average waiting time
  • 11. Convoy Effect Pid AT BT WT AWT P1 0 100 0 P2 1 1 99 Create Gantt Chart Pid AT BT WT AWT P1 1 100 1 P2 0 1 0 Create Gantt Chart Smaller process have to wait for long time for bigger process to release CPU
  • 12. Advantages  Easy to learn  Easy to understand  Easy to implement  We used for background process where execution is not urgent
  • 13. Disadvantages  Suffer from Convoy effect  Normally long average waiting time  No consideration to burst time or arrival time/Priority  Should not be used for interactive system
  • 14. Shortest job first (non-preemptive) shortest remaining time first(SRTF) (preemptive)  Out of all available process CPU is assigned to the process having smallest burst time requirement no priority, no seniority  If there is tie first Come First serve is used to break tie  Can we used both with non primitive and primitive approach  Primitive version STRF is also called as optimal as it currently minimum average waiting time
  • 15. Example of SJF Process Arrivall Time Burst Time P1 1 6 P2 2 8 P3 4 7 P4 0 3  SJF scheduling chart  Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P3 0 3 24 P4 P1 169 P2
  • 16. SJF (non-preemptive) Pid AT BT TAT WT A 3 1 B 1 4 C 4 2 D 0 6 E 2 3 Create Gantt Chart Calculate Waiting Time of Processes
  • 17. Example of Shortest-remaining-time-first  Now we add the concepts of varying arrival times and preemption to the analysis Process Arrival Time Burst 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
  • 18. SRTF(Pre-emptive) Pid AT BT TAT WT A 3 4 B 5 3 C 0 2 D 5 1 E 4 3 Create Gantt Chart Calculate Waiting Time of Processes
  • 19. Advantages and disadvantages of shortest job first scheduling algorithm Advantages  SRTF guarantees minimal average waiting time  Standard for other algorithm in terms of average waiting time  Better Average response time compare to First Come First serve Disadvantages  Algorithm cannot be implemented as there is no way to know the burst time of a process  Process with the longest CPU burst time requirement will go into starvation  No idea of priority, process with large burst time have work response time
  • 20. Priority Algorithm  Here a priority is associated with each process  At any instance of time out of all available process, CPU is allocated to the process which posses the highest Priority  Tie is broken with FCFS order  No importance to arrival time or burst time  Supports both non pre-emptive and pre-emptive version
  • 21. Continue..  A priority number (integer) is associated with each process  The CPU is allocated to the process with the 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
  • 22. Example of Priority Scheduling(Non-preemptive) Process Arrival Time Burst Time Priority P1 1 10 5 P2 0 1 3 P3 2 2 5 P4 3 1 4 P5 1 5 7 Priority scheduling Gantt Chart  Average waiting time
  • 23. Non Pre-emptive Pid AT BT Priority TAT WT P1 0 4 2 P2 1 3 3 P3 2 1 4 P4 3 5 5 P5 4 2 5 Create Gantt Chart Calculate Waiting Time of Processes
  • 24. Pre-emptive Pid AT BT Priority TAT WT P1 0 4 2 P2 1 3 3 P3 2 1 4 P4 3 5 5 P5 4 2 5 Create Gantt Chart Calculate Waiting Time of Processes
  • 25. Advantages and disadvantages of priority scheduling algorithm Advantages  Provide a facility of priority specially for system process  Allows to run important process first even if it is a user process Disadvantages  Here process with smaller priority may starve for CPU  No idea of response time or waiting time  Note aging is a technique of gradually increasing the priority of process that wait in the system for long time
  • 26. Round Robin (RR)  Each process gets a small unit of CPU time (time quantum q), 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.  Timer interrupts every quantum to schedule next process  Performance  q large  FIFO  q small  q must be large with respect to context switch, otherwise overhead is too high
  • 27. Continue.  It is design for time sharing system where it is not necessary to complete one process and then start another, but to be responsive and divide time of CPU among the process in the ready state  Here ready q to be treated as circular queue  We will fix the time quantum up to which process can hold the CPU in one go within which either a process terminates or process must release the CPU and re-enter in the circular queue and wait for the next chance  Round Robin is called preemptive in nature
  • 28. Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3  The Gantt chart is:  Typically, higher average turnaround than SJF, but better response  q should be large compared to context switch time  q usually 10ms to 100ms, context switch < 10 usec P P P1 1 1 0 18 3026144 7 10 22 P2 P3 P1 P1 P1
  • 29. Pre-emptive Pid AT BT TAT WT A 0 5 B 1 3 C 2 1 D 3 2 E 4 3 TQ=2 Create Queue Create Gantt Chart Calculate Waiting Time of Processes
  • 30. Advantages and disadvantages of Round Robin scheduling algorithm  Advantages  Perform best in terms of average response time  Works well in call to time sharing system, client server architecture and interactive system  Kind of shortest job first implementation  Disadvantages  Longer process may starve  Performance depends heavily on time Quantum  No idea of reality
  • 31. 1. The following is the set of processes whose arrival time, burst time and the priorities are given below: S.No. Process Arrival time (in ms) Bunt Time(in ms) Priority 1 P1 0 10 5 2 P2 0 5 2 3 P3 2 3 1 4 P4 5 20 4 5 P5 10 2 3 If Shortest job first ( vith pre-emption) scheduling policy and Priority scheduling policy(with pre- emption) is used then, what will be the average waiting time in both the cases? Ops: A. 5.6 ms, 8 ms B. None of the mentioned options C. 6.8 ms, 7.6 ms D. 0 5.6 ms, 7.6 ms Question