SlideShare a Scribd company logo
Chapter 5
CPU Scheduling (Algorithms)
5.2 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Chapter 5: CPU Scheduling
 5.1 Basic Concepts
 5.2 Scheduling Criteria
 5.3 Scheduling Algorithms
5.1 Basic Concepts
5.4 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Basic Concepts
 Maximum CPU utilization is obtained with multiprogramming
 Several processes are kept in memory at one time
 Every time a running process has to wait, another process can take
over use of the CPU
 Scheduling of the CPU is fundamental to operating system design
 Process execution consists of a cycle of a CPU time burst and an I/O
time burst (i.e. wait) as shown on the next slide
 Processes alternate between these two states (i.e., CPU burst and I/O
burst)
 Eventually, the final CPU burst ends with a system request to
terminate execution
5.5 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
CPU Scheduler
 The CPU scheduler selects from among the processes in memory that are ready to
execute and allocates the CPU to one of them
 CPU scheduling is affected by the following set of circumstances:
1. (N) A process switches from running to waiting state
2. (P) A process switches from running to ready state
3. (P) A process switches from waiting to ready state
4. (N) A processes switches from running to terminated state
 Circumstances 1 and 4 are non-preemptive; they offer no schedule choice
 Circumstances 2 and 3 are pre-emptive; they can be scheduled
5.6 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Dispatcher
 The dispatcher module gives control of the CPU to the process selected by
the short-term scheduler; this involves:
 switching context
 switching to user mode
 jumping to the proper location in the user program to restart that
program
 The dispatcher needs to run as fast as possible, since it is invoked during
process context switch
 The time it takes for the dispatcher to stop one process and start another
process is called dispatch latency
5.2 Scheduling Criteria
5.8 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
What is Scheduling in Operating Systems?
 In computing, scheduling is the action of assigning resources to
perform tasks
 The process scheduling is the activity of the process manager
that handles the removal of the running process from the CPU
and the selection of another process on the basis of a particular
strategy
 Process scheduling is an essential part of a Multiprogramming
operating systems
5.9 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Scheduling Criteria
 Different CPU scheduling algorithms have different properties
 The choice of a particular algorithm may favor one class of processes over another
 In choosing which algorithm to use, the properties of the various algorithms should be considered
 Criteria for comparing CPU scheduling algorithms may include the following
 CPU utilization – percent of time that the CPU is busy executing a process
 Throughput – number of processes that are completed per time unit
 Response time – amount of time it takes from when a request was submitted until the first
response occurs (but not the time it takes to output the entire response)
 Waiting time – the amount of time before a process starts after first entering the ready queue
(or the sum of the amount of time a process has spent waiting in the ready queue)
 Turnaround time – amount of time to execute a particular process from the time of
submission through the time of completion
5.10 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Optimization Criteria
 It is desirable to
 Maximize CPU utilization
 Maximize throughput
 Minimize turnaround time
 Minimize start time
 Minimize waiting time
 Minimize response time
 In most cases, we strive to optimize the average measure of each metric
 In other cases, it is more important to optimize the minimum or maximum
values rather than the average
5.11 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Key terms
 Turnaround time = Exit time - Arrival time
 Example: if a Process arrives at 10 and exits at 12 the turnaround time is 12-10=2
 Burst time: Burst time is the total time taken by the process for its execution on the CPU.
 Waiting time = Turnaround time - Burst time
 Service time: The amount of CPU time that a process will need before it either finishes or
voluntarily exits the CPU
 Average Waiting time: is the total time spent by the process in the ready state waiting for
CPU
 Average turnaround time: Turnaround time of all processes in the system
5.12 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
What is Gantt Chart?
 The chart is named after Henry Gantt (1861–1919),
 A Gantt chart is a type of bar chart that illustrates a project
schedule
5.13 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
What is Gantt chart ?
 A Gantt chart is a useful graphical tool which shows activities or tasks
performed against time. It is also known as visual presentation of a project where
the activities are broken down and displayed on a chart which makes it is easy
to understand and interpret.
5.3a Single Processor Scheduling
Algorithms
5.15 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Single Processor Scheduling
Algorithms
• First Come, First Served (FCFS)
• Shortest Job First (SJF)
• Priority
• Round Robin (RR)
First Come, First Served (FCFS)
Scheduling
5.17 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Some Key Terms Scheduling
 Burst Time (BT): This is the time required by the process for its
execution.
 Turnaround Time = CT( Completion time )-AT( Arrival Time)
 Waiting Time (WT): The time spent by a process waiting in the ready
queue for getting the CPU.
 Waiting time = Turnaround time - Burst time
5.18 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
First-Come, First-Served (FCFS) Scheduling
Process Burst Time
P1 24
P2 3
P3 3
 With FCFS, the process that requests the CPU first is allocated the CPU first
 Case #1: 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
 Average turn-around time: (24 + 27 + 30)/3 = 27
P1 P2 P3
24 27 30
0
5.19 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
FCFS Scheduling (Cont.)
 Case #2: Suppose that the processes arrive in the order: P2 , P3 , P1
 The Gantt chart for the schedule is:
 Waiting time for P1 = 6; P2 = 0; P3 = 3
 Average waiting time: (6 + 0 + 3)/3 = 3 (Much better than Case #1)
 Average turn-around time: (3 + 6 + 30)/3 = 13
 Case #1 is an example of the convoy effect; all the other processes wait for one
long-running process to finish using the CPU
 This problem results in lower CPU and device utilization; Case #2 shows that
higher utilization might be possible if the short processes were allowed to run
first
 The FCFS scheduling algorithm is non-preemptive
 Once the CPU has been allocated to a process, that process keeps the CPU
until it releases it either by terminating or by requesting I/O
 It is a troublesome algorithm for time-sharing systems
P1
P3
P2
6
3 30
0
Shortest Job First (SJF) Scheduling
5.21 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Shortest-Job-First (SJF) Scheduling
( Shortest Remaining Time First)(SRTF)
 The SJF algorithm associates with each process the length of its next CPU
burst
 When the CPU becomes available, it is assigned to the process that has the
smallest next CPU burst (in the case of matching bursts, FCFS is used)
 Two schemes:
 Nonpreemptive – once the CPU is given to the process, it cannot be
preempted until it completes its CPU burst
 Preemptive – if a new process arrives with a CPU burst length less than
the remaining time of the current executing process, preempt. This
scheme is know as the Shortest-Remaining-Time-First (SRTF)
5.22 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Process Arrival Time Burst Time
P1 0.0 6
P2 0.0 4
P3 0.0 1
P4 0.0 5
 SJF (non-preemptive, simultaneous arrival)
 Average waiting time = (0 + 1 + 5 + 10)/4 = 4
 Average turn-around time = (1 + 5 + 10 + 16)/4 = 8
Example #1: Non-Preemptive SJF
(simultaneous arrival)
P1
P3 P2
5
1 16
0
P4
10
5.23 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (non-preemptive, varied arrival times)
 Average waiting time
= ( (0 – 0) + (8 – 2) + (7 – 4) + (12 – 5) )/4
= (0 + 6 + 3 + 7)/4 = 4
 Average turn-around time:
= ( (7 – 0) + (12 – 2) + (8 - 4) + (16 – 5))/4
= ( 7 + 10 + 4 + 11)/4 = 8
Example #2: Non-Preemptive SJF
(varied arrival times)
P1 P3 P2
7
3 16
0
P4
8 12
Waiting time : sum of time that a process has spent waiting in the ready queue
5.24 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
From VTU Question Papers
5.25 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
From VTU question Paper Sept 2020
5.26 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Shortest Remaining Time First
(SJF-Preemptive)
 SRTF, Which Stands for Shortest Remaining Time
First is a scheduling algorithm used in Operating
Systems, which can also be called as the preemptive
version of the SJF scheduling algorithm
5.27 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Example #3: Preemptive SJF
(Shortest-remaining-time-first)
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (preemptive, varied arrival times)
 Average waiting time
=( [(0 – 0) + (11 - 2)] + [(2 – 2) + (5 – 4)] + (4 - 4) + (7 – 5) )/4
= 9 + 1 + 0 + 2)/4
= 3
 Average turn-around time = (16 + 5 + 1 + 6)/4 = 7
P1 P3
P2
4
2 11
0
P4
5 7
P2 P1
16
Waiting time : sum of time that a process has spent waiting in the ready queue
5.28 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Example on SRTF
5.29 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Example on SRTF
Priority Scheduling
5.31 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Priority Scheduling
 The SJF algorithm is a special case of the general priority scheduling algorithm
 A priority number (integer) is associated with each process
 The CPU is allocated to the process with the highest priority (smallest integer = highest priority)
 Priority scheduling can be either preemptive or non-preemptive
 A preemptive: approach will preempt the CPU if the priority of the newly-arrived process is
higher than the priority of the currently running process
 A non-preemptive approach will simply put the new process (with the highest priority) at the
head of the ready queue
 SJF is a priority scheduling algorithm where priority is the predicted next CPU burst time
 The main problem with priority scheduling is starvation, that is, low priority processes may never
execute
 A solution is aging; as time progresses, the priority of a process in the ready queue is increased
5.32 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Priority-Non-premptive
5.33 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Process Completion
Time
Turnaround
Time
Waiting Time
P1 05 05 0
P2 14 13 10
P3 22 20 12
P4 11 08 02
Average 11.5 06
Average Turnaround time=11.5 ms
Average Waiting time =06 ms
5.34 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Preemptive Priority Scheduling algorithm
PID Arrival Time Burst Time Priority
P1 0 11 2
P2 5 28 0
P3 12 2 3
P4 2 10 1
P5 9 16 4
P1 P4 P2 P4 P1 P3 P5
2
0 5 33 40 49 51 67
AWT=29
5.35 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Round Robin (RR) Scheduling
5.36 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Round Robin (RR) Scheduling
 In the round robin algorithm, each process gets a small unit of CPU time (a 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 of the round robin algorithm
 q large  FCFS
 q small  q must be greater than the context switch time; otherwise, the
overhead is too high
 One rule of thumb is that 80% of the CPU bursts should be shorter than the
time quantum
5.37 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Roun Robin With Different arrival Time
Example
5.38 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Ready Queue Table
During Arrival 0 P1 Arrives
After Completion of First Time
quantum of P1
P2 & P3 Arrives
Ready Queue will be like this P2-----P3-----P1
When P2 Completes its Time
Quantum
P4 and P5 arrives
Ready Queue will be like this P3-----P1-----P4----P5---P2
5.39 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
Round Robin with Diiferent Arrival Time
Process Exit Time TAT Waiting Time
P1 15 15-0=15 15-8=7
P2 23 22-1=22 22-6=16
P3 11 11-3=08 08-3=5
P4 17 17-5=12 12-2=10
P5 21 21-06=15 15-4=11
Avg 72/5=14.4 49/5=9.8
5.40 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005
5 is Highest and 0 is least

More Related Content

PPTX
Chapter4
PPTX
ch5.pptx CUP Scheduling and its details in OS
PPTX
CPU SCHEDULINGCPU SCHEDULINGCPU SCHEDULINGCPU SCHEDULING.pptx
PPTX
Operating System - CPU Scheduling Introduction
PDF
ch5_EN_CPUSched_2022.pdf
PDF
CPU scheduling ppt file
PPT
oprations of internet.ppt
Chapter4
ch5.pptx CUP Scheduling and its details in OS
CPU SCHEDULINGCPU SCHEDULINGCPU SCHEDULINGCPU SCHEDULING.pptx
Operating System - CPU Scheduling Introduction
ch5_EN_CPUSched_2022.pdf
CPU scheduling ppt file
oprations of internet.ppt

Similar to SCHEDULING.ppt (20)

PDF
Ch5 cpu-scheduling
PDF
ch5_EN_CPUSched.pdf
PPTX
Operating systems chapter 5 silberschatz
PPTX
OS-CPU-Scheduling-chap5.pptx
PPT
Module3 CPU Scheduling.ppt
PPT
CPU scheduling are using in operating systems.ppt
PPT
ch6.ppt
PPT
PPT
Various CPU Scheduling Algorithms in OS.ppt
PPT
scheduling.ppt
PPT
ch6.ppt
PPT
ch6 (2).ppt operating system by williamm
PPT
ch6.ppt
PDF
operating system in computer science .pdf
PDF
operating system in computer science ch05.pdf
PDF
cloud computing chapter one in computer science
PPT
ch5jnkhhkjhjkhhkhkjhuyuyiuyiyiuyuiyuyu-1.ppt
PPT
Scheduling topic in operating systems (OS).
PDF
W-ch06.pdfcentral processing unit scheduling
PPTX
Operating Systems CPU Scheduling Process
Ch5 cpu-scheduling
ch5_EN_CPUSched.pdf
Operating systems chapter 5 silberschatz
OS-CPU-Scheduling-chap5.pptx
Module3 CPU Scheduling.ppt
CPU scheduling are using in operating systems.ppt
ch6.ppt
Various CPU Scheduling Algorithms in OS.ppt
scheduling.ppt
ch6.ppt
ch6 (2).ppt operating system by williamm
ch6.ppt
operating system in computer science .pdf
operating system in computer science ch05.pdf
cloud computing chapter one in computer science
ch5jnkhhkjhjkhhkhkjhuyuyiuyiyiuyuiyuyu-1.ppt
Scheduling topic in operating systems (OS).
W-ch06.pdfcentral processing unit scheduling
Operating Systems CPU Scheduling Process
Ad

Recently uploaded (20)

PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
DOCX
573137875-Attendance-Management-System-original
PPTX
Geodesy 1.pptx...............................................
PDF
PPT on Performance Review to get promotions
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
composite construction of structures.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Construction Project Organization Group 2.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Welding lecture in detail for understanding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
573137875-Attendance-Management-System-original
Geodesy 1.pptx...............................................
PPT on Performance Review to get promotions
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
additive manufacturing of ss316l using mig welding
composite construction of structures.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
bas. eng. economics group 4 presentation 1.pptx
Sustainable Sites - Green Building Construction
R24 SURVEYING LAB MANUAL for civil enggi
Construction Project Organization Group 2.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Welding lecture in detail for understanding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Ad

SCHEDULING.ppt

  • 2. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling  5.1 Basic Concepts  5.2 Scheduling Criteria  5.3 Scheduling Algorithms
  • 4. 5.4 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Basic Concepts  Maximum CPU utilization is obtained with multiprogramming  Several processes are kept in memory at one time  Every time a running process has to wait, another process can take over use of the CPU  Scheduling of the CPU is fundamental to operating system design  Process execution consists of a cycle of a CPU time burst and an I/O time burst (i.e. wait) as shown on the next slide  Processes alternate between these two states (i.e., CPU burst and I/O burst)  Eventually, the final CPU burst ends with a system request to terminate execution
  • 5. 5.5 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 CPU Scheduler  The CPU scheduler selects from among the processes in memory that are ready to execute and allocates the CPU to one of them  CPU scheduling is affected by the following set of circumstances: 1. (N) A process switches from running to waiting state 2. (P) A process switches from running to ready state 3. (P) A process switches from waiting to ready state 4. (N) A processes switches from running to terminated state  Circumstances 1 and 4 are non-preemptive; they offer no schedule choice  Circumstances 2 and 3 are pre-emptive; they can be scheduled
  • 6. 5.6 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Dispatcher  The dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:  switching context  switching to user mode  jumping to the proper location in the user program to restart that program  The dispatcher needs to run as fast as possible, since it is invoked during process context switch  The time it takes for the dispatcher to stop one process and start another process is called dispatch latency
  • 8. 5.8 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 What is Scheduling in Operating Systems?  In computing, scheduling is the action of assigning resources to perform tasks  The process scheduling is the activity of the process manager that handles the removal of the running process from the CPU and the selection of another process on the basis of a particular strategy  Process scheduling is an essential part of a Multiprogramming operating systems
  • 9. 5.9 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Scheduling Criteria  Different CPU scheduling algorithms have different properties  The choice of a particular algorithm may favor one class of processes over another  In choosing which algorithm to use, the properties of the various algorithms should be considered  Criteria for comparing CPU scheduling algorithms may include the following  CPU utilization – percent of time that the CPU is busy executing a process  Throughput – number of processes that are completed per time unit  Response time – amount of time it takes from when a request was submitted until the first response occurs (but not the time it takes to output the entire response)  Waiting time – the amount of time before a process starts after first entering the ready queue (or the sum of the amount of time a process has spent waiting in the ready queue)  Turnaround time – amount of time to execute a particular process from the time of submission through the time of completion
  • 10. 5.10 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Optimization Criteria  It is desirable to  Maximize CPU utilization  Maximize throughput  Minimize turnaround time  Minimize start time  Minimize waiting time  Minimize response time  In most cases, we strive to optimize the average measure of each metric  In other cases, it is more important to optimize the minimum or maximum values rather than the average
  • 11. 5.11 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Key terms  Turnaround time = Exit time - Arrival time  Example: if a Process arrives at 10 and exits at 12 the turnaround time is 12-10=2  Burst time: Burst time is the total time taken by the process for its execution on the CPU.  Waiting time = Turnaround time - Burst time  Service time: The amount of CPU time that a process will need before it either finishes or voluntarily exits the CPU  Average Waiting time: is the total time spent by the process in the ready state waiting for CPU  Average turnaround time: Turnaround time of all processes in the system
  • 12. 5.12 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 What is Gantt Chart?  The chart is named after Henry Gantt (1861–1919),  A Gantt chart is a type of bar chart that illustrates a project schedule
  • 13. 5.13 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 What is Gantt chart ?  A Gantt chart is a useful graphical tool which shows activities or tasks performed against time. It is also known as visual presentation of a project where the activities are broken down and displayed on a chart which makes it is easy to understand and interpret.
  • 14. 5.3a Single Processor Scheduling Algorithms
  • 15. 5.15 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Single Processor Scheduling Algorithms • First Come, First Served (FCFS) • Shortest Job First (SJF) • Priority • Round Robin (RR)
  • 16. First Come, First Served (FCFS) Scheduling
  • 17. 5.17 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Some Key Terms Scheduling  Burst Time (BT): This is the time required by the process for its execution.  Turnaround Time = CT( Completion time )-AT( Arrival Time)  Waiting Time (WT): The time spent by a process waiting in the ready queue for getting the CPU.  Waiting time = Turnaround time - Burst time
  • 18. 5.18 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 First-Come, First-Served (FCFS) Scheduling Process Burst Time P1 24 P2 3 P3 3  With FCFS, the process that requests the CPU first is allocated the CPU first  Case #1: 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  Average turn-around time: (24 + 27 + 30)/3 = 27 P1 P2 P3 24 27 30 0
  • 19. 5.19 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 FCFS Scheduling (Cont.)  Case #2: Suppose that the processes arrive in the order: P2 , P3 , P1  The Gantt chart for the schedule is:  Waiting time for P1 = 6; P2 = 0; P3 = 3  Average waiting time: (6 + 0 + 3)/3 = 3 (Much better than Case #1)  Average turn-around time: (3 + 6 + 30)/3 = 13  Case #1 is an example of the convoy effect; all the other processes wait for one long-running process to finish using the CPU  This problem results in lower CPU and device utilization; Case #2 shows that higher utilization might be possible if the short processes were allowed to run first  The FCFS scheduling algorithm is non-preemptive  Once the CPU has been allocated to a process, that process keeps the CPU until it releases it either by terminating or by requesting I/O  It is a troublesome algorithm for time-sharing systems P1 P3 P2 6 3 30 0
  • 20. Shortest Job First (SJF) Scheduling
  • 21. 5.21 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Shortest-Job-First (SJF) Scheduling ( Shortest Remaining Time First)(SRTF)  The SJF algorithm associates with each process the length of its next CPU burst  When the CPU becomes available, it is assigned to the process that has the smallest next CPU burst (in the case of matching bursts, FCFS is used)  Two schemes:  Nonpreemptive – once the CPU is given to the process, it cannot be preempted until it completes its CPU burst  Preemptive – if a new process arrives with a CPU burst length less than the remaining time of the current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF)
  • 22. 5.22 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Process Arrival Time Burst Time P1 0.0 6 P2 0.0 4 P3 0.0 1 P4 0.0 5  SJF (non-preemptive, simultaneous arrival)  Average waiting time = (0 + 1 + 5 + 10)/4 = 4  Average turn-around time = (1 + 5 + 10 + 16)/4 = 8 Example #1: Non-Preemptive SJF (simultaneous arrival) P1 P3 P2 5 1 16 0 P4 10
  • 23. 5.23 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (non-preemptive, varied arrival times)  Average waiting time = ( (0 – 0) + (8 – 2) + (7 – 4) + (12 – 5) )/4 = (0 + 6 + 3 + 7)/4 = 4  Average turn-around time: = ( (7 – 0) + (12 – 2) + (8 - 4) + (16 – 5))/4 = ( 7 + 10 + 4 + 11)/4 = 8 Example #2: Non-Preemptive SJF (varied arrival times) P1 P3 P2 7 3 16 0 P4 8 12 Waiting time : sum of time that a process has spent waiting in the ready queue
  • 24. 5.24 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 From VTU Question Papers
  • 25. 5.25 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 From VTU question Paper Sept 2020
  • 26. 5.26 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Shortest Remaining Time First (SJF-Preemptive)  SRTF, Which Stands for Shortest Remaining Time First is a scheduling algorithm used in Operating Systems, which can also be called as the preemptive version of the SJF scheduling algorithm
  • 27. 5.27 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Example #3: Preemptive SJF (Shortest-remaining-time-first) Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (preemptive, varied arrival times)  Average waiting time =( [(0 – 0) + (11 - 2)] + [(2 – 2) + (5 – 4)] + (4 - 4) + (7 – 5) )/4 = 9 + 1 + 0 + 2)/4 = 3  Average turn-around time = (16 + 5 + 1 + 6)/4 = 7 P1 P3 P2 4 2 11 0 P4 5 7 P2 P1 16 Waiting time : sum of time that a process has spent waiting in the ready queue
  • 28. 5.28 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Example on SRTF
  • 29. 5.29 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Example on SRTF
  • 31. 5.31 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Priority Scheduling  The SJF algorithm is a special case of the general priority scheduling algorithm  A priority number (integer) is associated with each process  The CPU is allocated to the process with the highest priority (smallest integer = highest priority)  Priority scheduling can be either preemptive or non-preemptive  A preemptive: approach will preempt the CPU if the priority of the newly-arrived process is higher than the priority of the currently running process  A non-preemptive approach will simply put the new process (with the highest priority) at the head of the ready queue  SJF is a priority scheduling algorithm where priority is the predicted next CPU burst time  The main problem with priority scheduling is starvation, that is, low priority processes may never execute  A solution is aging; as time progresses, the priority of a process in the ready queue is increased
  • 32. 5.32 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Priority-Non-premptive
  • 33. 5.33 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Process Completion Time Turnaround Time Waiting Time P1 05 05 0 P2 14 13 10 P3 22 20 12 P4 11 08 02 Average 11.5 06 Average Turnaround time=11.5 ms Average Waiting time =06 ms
  • 34. 5.34 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Preemptive Priority Scheduling algorithm PID Arrival Time Burst Time Priority P1 0 11 2 P2 5 28 0 P3 12 2 3 P4 2 10 1 P5 9 16 4 P1 P4 P2 P4 P1 P3 P5 2 0 5 33 40 49 51 67 AWT=29
  • 35. 5.35 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Round Robin (RR) Scheduling
  • 36. 5.36 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Round Robin (RR) Scheduling  In the round robin algorithm, each process gets a small unit of CPU time (a 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 of the round robin algorithm  q large  FCFS  q small  q must be greater than the context switch time; otherwise, the overhead is too high  One rule of thumb is that 80% of the CPU bursts should be shorter than the time quantum
  • 37. 5.37 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Roun Robin With Different arrival Time Example
  • 38. 5.38 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Ready Queue Table During Arrival 0 P1 Arrives After Completion of First Time quantum of P1 P2 & P3 Arrives Ready Queue will be like this P2-----P3-----P1 When P2 Completes its Time Quantum P4 and P5 arrives Ready Queue will be like this P3-----P1-----P4----P5---P2
  • 39. 5.39 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 Round Robin with Diiferent Arrival Time Process Exit Time TAT Waiting Time P1 15 15-0=15 15-8=7 P2 23 22-1=22 22-6=16 P3 11 11-3=08 08-3=5 P4 17 17-5=12 12-2=10 P5 21 21-06=15 15-4=11 Avg 72/5=14.4 49/5=9.8
  • 40. 5.40 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7th Edition, Feb 2, 2005 5 is Highest and 0 is least