SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tendances (20)

Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Distributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithmDistributed system lamport's and vector algorithm
Distributed system lamport's and vector algorithm
 
Round Robin Algorithm.pptx
Round Robin Algorithm.pptxRound Robin Algorithm.pptx
Round Robin Algorithm.pptx
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin scheduling
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Scheduling
 
FCFS scheduling OS
FCFS scheduling OSFCFS scheduling OS
FCFS scheduling OS
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Shortest Job First
Shortest Job FirstShortest Job First
Shortest Job First
 
MULTILEVEL QUEUE SCHEDULING
MULTILEVEL QUEUE SCHEDULINGMULTILEVEL QUEUE SCHEDULING
MULTILEVEL QUEUE SCHEDULING
 
Priority scheduling algorithms
Priority scheduling algorithmsPriority scheduling algorithms
Priority scheduling algorithms
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
first come first serve scheduling in os
first come first serve scheduling in os first come first serve scheduling in os
first come first serve scheduling in os
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Deadlock
DeadlockDeadlock
Deadlock
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 

Similaire à CPU scheduling

Similaire à 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
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
OSCh6
OSCh6OSCh6
OSCh6
 
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
 
Csc4320 chapter 5 2
Csc4320 chapter 5 2Csc4320 chapter 5 2
Csc4320 chapter 5 2
 
Os..
Os..Os..
Os..
 
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
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 

Dernier

Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Dernier (20)

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 

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