SlideShare uma empresa Scribd logo
1 de 17
Silberschatz, Galvin and Gagne 2002
1.1
CPU Scheduling
Basic Concepts
• Maximum CPU utilization obtained with multiprogramming.
• In a uniprocessor system, only one process may run a time, any other process
must wait until the CPU is free and can be rescheduled.
CPU-I/O Burst Cycle
• CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU
execution and I/O wait. Process alternate between these two states.
• Process execution begins with a CPU burst. That is followed by an I/O burst,
then another CPU burst, then another I/O burst, and so on.
• Eventually, the last CPU burst will end with a system request to terminate
execution, rather than with another I/O burst.
Silberschatz, Galvin and Gagne 2002
1.2
• An I/O bound program would typically have many very short CPU bursts.
• A CPU-bound program might have a few very long CPU bursts.
• This distribution can help us to select an appropriate CPU-scheduling algorithm.
Alternating Sequence of CPU And I/O Bursts
Silberschatz, Galvin and Gagne 2002
1.3
CPU Scheduler
 Whenever the CPU becomes idle, the operating system must select
one of the processes in the ready queue to be executed.
 The selection process is carried out by the short-term scheduler (CPU
scheduler).
 The scheduler selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them.
 CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state.
2. Switches from running to ready state.
3. Switches from waiting to ready.
4. Terminates.
Silberschatz, Galvin and Gagne 2002
1.4
Preemptive Scheduling
CPU scheduling decisions may take place under the following four circumstances:
1. When a process switches from the running state to the waiting state (for
example, I/O request, or invocation of wait for the termination of one of the
child processes)
2. When a process switches from the running state to the ready state ( for
example, when an interrupt occurs)
3. When a process switches from the waiting state to the ready state (for
example, completion of I/O)
4. When a process termination
In circumstances 1 and 4, there is no choice in terms of scheduling. A new process
(if one exists in the ready queue) must be selected for execution. There is a
choice, however, in circumstances 2 and 3.
When scheduling takes place only under circumstances 1 and 4, the scheduling
scheme is called nonpreemptive; otherwise, the scheduling scheme is
preemptive.
Silberschatz, Galvin and Gagne 2002
1.5
Dispatcher
 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
 Dispatch latency – time it takes for the dispatcher to stop one process
and start another running.
Silberschatz, Galvin and Gagne 2002
1.6
Scheduling Criteria
 CPU utilization – keep the CPU as busy as possible.
 Throughput – No. of processes that complete their execution per time
unit.
 Turnaround time – amount of time to execute a particular process.
 Waiting time – amount of time a process has been waiting in the ready
queue.
 Response time – amount of time it takes from when a request was
submitted until the first response is produced, not output (for time-
sharing environment)
• Different CPU scheduling algorithms have different properties.
• 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.
Silberschatz, Galvin and Gagne 2002
1.7
CPU Scheduling Algorithms
1. FCFS
2. SJF
3. Priority scheduling
4. Round Robin scheduling
Operating System Concepts
Silberschatz, Galvin and Gagne 2002
1.8
SO 2 : Explain the procedures in 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
P1 P2 P3
24 27 30
0
Silberschatz, Galvin and Gagne 2002
1.9
FCFS Scheduling (Cont.)
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 previous case.
 Convoy effect short process behind long process
P1
P3
P2
6
3 30
0
Silberschatz, Galvin and Gagne 2002
1.10
SO 3: Demonstrate Shortest-Job-First (SJR)
Scheduling and Priority scheduling
 Associate with each process the length of its next CPU
burst. Use these lengths to schedule the process with the
shortest time.
 Two schemes:
 nonpreemptive – once CPU given to the process it cannot
be preempted until completes its CPU burst.
 preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
 SJF is optimal – gives minimum average waiting time for
a given set of processes.
Silberschatz, Galvin and Gagne 2002
1.11
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (non-preemptive)
 Average waiting time = (0 + 6 + 3 + 7)/4 - 4
Example of Non-Preemptive SJF
P1 P3 P2
7
3 16
0
P4
8 12
Silberschatz, Galvin and Gagne 2002
1.12
Example of Preemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 SJF (preemptive)
 Average waiting time = (9 + 1 + 0 +2)/4 - 3
P1 P3
P2
4
2 11
0
P4
5 7
P2 P1
16
Silberschatz, Galvin and Gagne 2002
1.13
Priority Scheduling
 A priority number (integer) is associated with each
process
 The CPU is allocated to the process with the highest
priority (smallest integer  highest priority).
 Preemptive
 nonpreemptive
 SJF is a priority scheduling where priority is the predicted
next CPU burst time.
 Problem  Starvation – low priority processes may never
execute.
 Solution  Aging – as time progresses increase the
priority of the process.
Silberschatz, Galvin and Gagne 2002
1.14
SO 4 : Determine the AWT and ATT using
Round Robin (RR) scheduling
 Each process gets a small unit of CPU time (time
quantum), usually 10-100 milliseconds. After this time
has elapsed, the process is preempted and added to the
end of the ready queue.
 If there are n processes in the ready queue and the time
quantum is q, then each process gets 1/n of the CPU time
in chunks of at most q time units at once. No process
waits more than (n-1)q time units.
 Performance
 q large  FIFO
 q small  q must be large with respect to context switch,
otherwise overhead is too high.
Silberschatz, Galvin and Gagne 2002
1.15
Example of RR with Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
 The Gantt chart is:
 Typically, higher average turnaround than SJF, but better
response.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Silberschatz, Galvin and Gagne 2002
1.16
Multiprocessor Scheduling
 Multiple processor scheduling or multiprocessor
scheduling focuses on designing the system's scheduling
function, which consists of more than one processor.
 Multiple CPUs share the load (load sharing) in multiprocessor
scheduling so that various processes run simultaneously
 In general, multiprocessor scheduling is complex as compared
to single processor scheduling
 In the multiprocessor scheduling, there are many processors,
and they are identical, and we can run any process at any time
 The multiple CPUs in the system are in close communication,
which shares a common bus, memory, and other peripheral
devices. So we can say that the system is tightly coupled.
 These systems are used when we want to process a bulk
amount of data, and these systems are mainly used in satellite,
weather forecasting, etc
Silberschatz, Galvin and Gagne 2002
1.17
Multiprocessor Scheduling
 Multiprocessor systems may e heterogeneous (different
kinds of CPUs) or homogenous (the same CPU). There
may be special scheduling constraints, such as devices
connected via a private bus to only one CPU
 There is no policy or rule which can be declared as the best
scheduling solution to a system with a single processor.
Similarly, there is no best scheduling solution for a system with
multiple processors as well

Mais conteúdo relacionado

Semelhante a U2-LP2.ppt

Semelhante a U2-LP2.ppt (20)

ch5_EN_CPUSched_2022.pdf
ch5_EN_CPUSched_2022.pdfch5_EN_CPUSched_2022.pdf
ch5_EN_CPUSched_2022.pdf
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Module3 CPU Scheduling.ppt
Module3 CPU Scheduling.pptModule3 CPU Scheduling.ppt
Module3 CPU Scheduling.ppt
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formatting
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Cpu scheduling final
Cpu scheduling finalCpu scheduling final
Cpu scheduling final
 
6 cpu scheduling
6 cpu scheduling6 cpu scheduling
6 cpu scheduling
 
Scheduling
SchedulingScheduling
Scheduling
 
OS_Ch05.pdf
OS_Ch05.pdfOS_Ch05.pdf
OS_Ch05.pdf
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Ch6: CPU Scheduling
Ch6: CPU SchedulingCh6: CPU Scheduling
Ch6: CPU Scheduling
 
Ch6 CPU Scheduling galvin
Ch6 CPU Scheduling galvinCh6 CPU Scheduling galvin
Ch6 CPU Scheduling galvin
 
OSCh6
OSCh6OSCh6
OSCh6
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
Ch5
Ch5Ch5
Ch5
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
ch5_EN_CPUSched.pdf
ch5_EN_CPUSched.pdfch5_EN_CPUSched.pdf
ch5_EN_CPUSched.pdf
 

Mais de AJAYVISHALRP

finalppt-150606051347-lva1-app6892.pptx
finalppt-150606051347-lva1-app6892.pptxfinalppt-150606051347-lva1-app6892.pptx
finalppt-150606051347-lva1-app6892.pptxAJAYVISHALRP
 
WH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptxWH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptxAJAYVISHALRP
 
Data Storage Access and Security.pptx
Data Storage Access and Security.pptxData Storage Access and Security.pptx
Data Storage Access and Security.pptxAJAYVISHALRP
 
disk scheduling algorithms.pptx
disk scheduling algorithms.pptxdisk scheduling algorithms.pptx
disk scheduling algorithms.pptxAJAYVISHALRP
 
WH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptxWH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptxAJAYVISHALRP
 

Mais de AJAYVISHALRP (10)

finalppt-150606051347-lva1-app6892.pptx
finalppt-150606051347-lva1-app6892.pptxfinalppt-150606051347-lva1-app6892.pptx
finalppt-150606051347-lva1-app6892.pptx
 
WH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptxWH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptx
 
Data Storage Access and Security.pptx
Data Storage Access and Security.pptxData Storage Access and Security.pptx
Data Storage Access and Security.pptx
 
U3-PPT-1 (1).ppt
U3-PPT-1 (1).pptU3-PPT-1 (1).ppt
U3-PPT-1 (1).ppt
 
U1-LP1.ppt
U1-LP1.pptU1-LP1.ppt
U1-LP1.ppt
 
disk scheduling algorithms.pptx
disk scheduling algorithms.pptxdisk scheduling algorithms.pptx
disk scheduling algorithms.pptx
 
1G1.pptx
1G1.pptx1G1.pptx
1G1.pptx
 
WH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptxWH PAPER PRESENTATION PPT.pptx
WH PAPER PRESENTATION PPT.pptx
 
sorting1.pptx
sorting1.pptxsorting1.pptx
sorting1.pptx
 
AI Pugal.pptx
AI Pugal.pptxAI Pugal.pptx
AI Pugal.pptx
 

Último

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Último (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

U2-LP2.ppt

  • 1. Silberschatz, Galvin and Gagne 2002 1.1 CPU Scheduling Basic Concepts • Maximum CPU utilization obtained with multiprogramming. • In a uniprocessor system, only one process may run a time, any other process must wait until the CPU is free and can be rescheduled. CPU-I/O Burst Cycle • CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait. Process alternate between these two states. • Process execution begins with a CPU burst. That is followed by an I/O burst, then another CPU burst, then another I/O burst, and so on. • Eventually, the last CPU burst will end with a system request to terminate execution, rather than with another I/O burst.
  • 2. Silberschatz, Galvin and Gagne 2002 1.2 • An I/O bound program would typically have many very short CPU bursts. • A CPU-bound program might have a few very long CPU bursts. • This distribution can help us to select an appropriate CPU-scheduling algorithm. Alternating Sequence of CPU And I/O Bursts
  • 3. Silberschatz, Galvin and Gagne 2002 1.3 CPU Scheduler  Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed.  The selection process is carried out by the short-term scheduler (CPU scheduler).  The scheduler selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them.  CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates.
  • 4. Silberschatz, Galvin and Gagne 2002 1.4 Preemptive Scheduling CPU scheduling decisions may take place under the following four circumstances: 1. When a process switches from the running state to the waiting state (for example, I/O request, or invocation of wait for the termination of one of the child processes) 2. When a process switches from the running state to the ready state ( for example, when an interrupt occurs) 3. When a process switches from the waiting state to the ready state (for example, completion of I/O) 4. When a process termination In circumstances 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must be selected for execution. There is a choice, however, in circumstances 2 and 3. When scheduling takes place only under circumstances 1 and 4, the scheduling scheme is called nonpreemptive; otherwise, the scheduling scheme is preemptive.
  • 5. Silberschatz, Galvin and Gagne 2002 1.5 Dispatcher  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  Dispatch latency – time it takes for the dispatcher to stop one process and start another running.
  • 6. Silberschatz, Galvin and Gagne 2002 1.6 Scheduling Criteria  CPU utilization – keep the CPU as busy as possible.  Throughput – No. of processes that complete their execution per time unit.  Turnaround time – amount of time to execute a particular process.  Waiting time – amount of time a process has been waiting in the ready queue.  Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time- sharing environment) • Different CPU scheduling algorithms have different properties. • 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.
  • 7. Silberschatz, Galvin and Gagne 2002 1.7 CPU Scheduling Algorithms 1. FCFS 2. SJF 3. Priority scheduling 4. Round Robin scheduling Operating System Concepts
  • 8. Silberschatz, Galvin and Gagne 2002 1.8 SO 2 : Explain the procedures in 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 P1 P2 P3 24 27 30 0
  • 9. Silberschatz, Galvin and Gagne 2002 1.9 FCFS Scheduling (Cont.) 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 previous case.  Convoy effect short process behind long process P1 P3 P2 6 3 30 0
  • 10. Silberschatz, Galvin and Gagne 2002 1.10 SO 3: Demonstrate Shortest-Job-First (SJR) Scheduling and Priority scheduling  Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time.  Two schemes:  nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst.  preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF).  SJF is optimal – gives minimum average waiting time for a given set of processes.
  • 11. Silberschatz, Galvin and Gagne 2002 1.11 Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (non-preemptive)  Average waiting time = (0 + 6 + 3 + 7)/4 - 4 Example of Non-Preemptive SJF P1 P3 P2 7 3 16 0 P4 8 12
  • 12. Silberschatz, Galvin and Gagne 2002 1.12 Example of Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  SJF (preemptive)  Average waiting time = (9 + 1 + 0 +2)/4 - 3 P1 P3 P2 4 2 11 0 P4 5 7 P2 P1 16
  • 13. Silberschatz, Galvin and Gagne 2002 1.13 Priority Scheduling  A priority number (integer) is associated with each process  The CPU is allocated to the process with the highest priority (smallest integer  highest priority).  Preemptive  nonpreemptive  SJF is a priority scheduling where priority is the predicted next CPU burst time.  Problem  Starvation – low priority processes may never execute.  Solution  Aging – as time progresses increase the priority of the process.
  • 14. Silberschatz, Galvin and Gagne 2002 1.14 SO 4 : Determine the AWT and ATT using Round Robin (RR) scheduling  Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.  If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.  Performance  q large  FIFO  q small  q must be large with respect to context switch, otherwise overhead is too high.
  • 15. Silberschatz, Galvin and Gagne 2002 1.15 Example of RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24  The Gantt chart is:  Typically, higher average turnaround than SJF, but better response. P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162
  • 16. Silberschatz, Galvin and Gagne 2002 1.16 Multiprocessor Scheduling  Multiple processor scheduling or multiprocessor scheduling focuses on designing the system's scheduling function, which consists of more than one processor.  Multiple CPUs share the load (load sharing) in multiprocessor scheduling so that various processes run simultaneously  In general, multiprocessor scheduling is complex as compared to single processor scheduling  In the multiprocessor scheduling, there are many processors, and they are identical, and we can run any process at any time  The multiple CPUs in the system are in close communication, which shares a common bus, memory, and other peripheral devices. So we can say that the system is tightly coupled.  These systems are used when we want to process a bulk amount of data, and these systems are mainly used in satellite, weather forecasting, etc
  • 17. Silberschatz, Galvin and Gagne 2002 1.17 Multiprocessor Scheduling  Multiprocessor systems may e heterogeneous (different kinds of CPUs) or homogenous (the same CPU). There may be special scheduling constraints, such as devices connected via a private bus to only one CPU  There is no policy or rule which can be declared as the best scheduling solution to a system with a single processor. Similarly, there is no best scheduling solution for a system with multiple processors as well