SlideShare a Scribd company logo
1 of 31
Download to read offline
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

More Related Content

What's hot (20)

Process management in os
Process management in osProcess management in os
Process management in os
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Operating System Scheduling Algorithms
Operating System Scheduling AlgorithmsOperating System Scheduling Algorithms
Operating System Scheduling Algorithms
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Fragmentaton
Fragmentaton Fragmentaton
Fragmentaton
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin scheduling
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Semaphore
SemaphoreSemaphore
Semaphore
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 
Interrupts
InterruptsInterrupts
Interrupts
 
P threads
P threadsP threads
P threads
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 

Similar to CPU scheduling

Similar to CPU scheduling (20)

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
 
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
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 

Recently uploaded

Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docxSUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docxNaveenVerma126
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS Bahzad5
 
Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)Bahzad5
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Graphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesGraphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesDIPIKA83
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Apollo Techno Industries Pvt Ltd
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfJulia Kaye
 
EPE3163_Hydro power stations_Unit2_Lect2.pptx
EPE3163_Hydro power stations_Unit2_Lect2.pptxEPE3163_Hydro power stations_Unit2_Lect2.pptx
EPE3163_Hydro power stations_Unit2_Lect2.pptxJoseeMusabyimana
 
OS Services, System call, Virtual Machine
OS Services, System call, Virtual MachineOS Services, System call, Virtual Machine
OS Services, System call, Virtual MachineDivya S
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Projectreemakb03
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide LaboratoryBahzad5
 
A Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationA Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationMohsinKhanA
 
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxLMW Machine Tool Division
 

Recently uploaded (20)

Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 
Présentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdfPrésentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdf
 
Litature Review: Research Paper work for Engineering
Litature Review: Research Paper work for EngineeringLitature Review: Research Paper work for Engineering
Litature Review: Research Paper work for Engineering
 
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docxSUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
SUMMER TRAINING REPORT ON BUILDING CONSTRUCTION.docx
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
 
Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)Lecture 1: Basics of trigonometry (surveying)
Lecture 1: Basics of trigonometry (surveying)
 
Présentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdfPrésentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdf
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Graphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesGraphics Primitives and CG Display Devices
Graphics Primitives and CG Display Devices
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
 
EPE3163_Hydro power stations_Unit2_Lect2.pptx
EPE3163_Hydro power stations_Unit2_Lect2.pptxEPE3163_Hydro power stations_Unit2_Lect2.pptx
EPE3163_Hydro power stations_Unit2_Lect2.pptx
 
Lecture 2 .pptx
Lecture 2                            .pptxLecture 2                            .pptx
Lecture 2 .pptx
 
OS Services, System call, Virtual Machine
OS Services, System call, Virtual MachineOS Services, System call, Virtual Machine
OS Services, System call, Virtual Machine
 
計劃趕得上變化
計劃趕得上變化計劃趕得上變化
計劃趕得上變化
 
Lecture 2 .pdf
Lecture 2                           .pdfLecture 2                           .pdf
Lecture 2 .pdf
 
Gender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 ProjectGender Bias in Engineer, Honors 203 Project
Gender Bias in Engineer, Honors 203 Project
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
 
A Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationA Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software Simulation
 
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptxVertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
Vertical- Machining - Center - VMC -LMW-Machine-Tool-Division.pptx
 

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