SlideShare uma empresa Scribd logo
1 de 32
Rushdi Shams, Dept of CSE, KUET 1
Operating Systems
CPU Scheduling
Version 1.0
Rushdi Shams, Dept of CSE, KUET 2
Basic Concepts
The objective of multiprogramming is to run
processes all time, keeping the CPU busy.
Uniprocessing system is different. Only one process
can run at a time- means processes have to wait until
the CPU is free.
Rushdi Shams, Dept of CSE, KUET 3
Basic Concepts
A process is executed until the completion of an IO
request
The CPU then sits idle and all this waiting time is
wasted
With multiprogramming, we keep several processes
in memory at one time.
When one process has to wait, the OS takes the CPU
away from that process and gives the CPU to another
process
Rushdi Shams, Dept of CSE, KUET 4
Basic Concepts
Almost all computer resources are scheduled before
use. The CPU is one of the primary resources. Thus,
its scheduling is central to operating systems
Rushdi Shams, Dept of CSE, KUET 5
CPU burst and IO burst
Rushdi Shams, Dept of CSE, KUET 6
CPU Scheduler
 Selects from 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
 Scheduling under 1 and 4 is nonpreemptive
 All other scheduling is preemptive
Rushdi Shams, Dept of CSE, KUET 7
CPU Scheduler
In case of Non-preemptive scheduling, the process
does not release the CPU unless it is finished (or
terminated) or going to the waiting state.
Rushdi Shams, Dept of CSE, KUET 8
Dispatcher
Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler; this
involves:
switching context
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
Rushdi Shams, Dept of CSE, KUET 9
Scheduling Criteria
CPU utilization
How much of the CPU is in operation, how much of it
is utilized to serve processes.
Measured in Percentage
Should be maximized
Rushdi Shams, Dept of CSE, KUET 10
Scheduling Criteria
Throughput
Number of processes executed and served per unit
time.
Measured in process per unit time
Should be maximized
Rushdi Shams, Dept of CSE, KUET 11
Scheduling Criteria
Turnaround time
Amount of time to execute a particular process
Interval between the submission of the process and
its completion
Should be minimized
Rushdi Shams, Dept of CSE, KUET 12
Scheduling Criteria
Waiting time
amount of time a process has been waiting in the
ready queue
Should be minimized
Rushdi Shams, Dept of CSE, KUET 13
Scheduling Criteria
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)
Should be minimized
Rushdi Shams, Dept of CSE, KUET 14
First Come, First Served (FCFS)
The simplest CPU Scheduling algorithm
The process that requests CPU first is allocated the
CPU first
Easily managed with a FIFO queue
Rushdi Shams, Dept of CSE, KUET 15
FCFS
Proces 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 300
Rushdi Shams, Dept of CSE, KUET 16
FCFS
Proces Burst Time
P1 24
P2 3
P3 3
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
P1P3P2
63 300
Rushdi Shams, Dept of CSE, KUET 17
Shortest Job First (SJF)
 Associate with each process the length of its next CPU burst.
Use these lengths to schedule the process with the shortest
time
 Two schemes:
 non-preemptive – 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 also called Shortest-Remaining-Time-First (SRTF)
 SJF is optimal – gives minimum average waiting time for a given
set of processes
Rushdi Shams, Dept of CSE, KUET 18
SJF
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
P1 P3 P2
73 160
P4
8 12
Rushdi Shams, Dept of CSE, KUET 19
SRTF
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 P3P2
42 110
P4
5 7
P2 P1
16
Rushdi Shams, Dept of CSE, KUET 20
Priority Scheduling
The SJF Algorithm is special case of Priority
Scheduling
A priority is associated with each process and the CPU
is given to the process with higher priority
If processes have equal priority, FCFS is followed
SJF is priority algorithm where
priority p = inverse of CPU burst
Priorities are generally some fixed range of numbers
such as 0 to 7 or 0 to 4,095
Rushdi Shams, Dept of CSE, KUET 21
Priority Scheduling
However, there is no agreement on the highest
priority- if it would be 0 or 4,095
Priorities can be external or internal
Internal priorities are number of files required to
execute the process, its memory usage, resources
required, time to compute, etc.
External priorities are set by outside computer-
mainly by human based on the choice of process,
economical factors, etc.
Rushdi Shams, Dept of CSE, KUET 22
Priority Scheduling
The Average Waiting Time is (6+0+16+18+1)/5=8.2 ms
Rushdi Shams, Dept of CSE, KUET 23
Priority Scheduling: Starvation
 Higher priority schedules prohibits lower priority
schedules for getting the CPU
 There are two possibilities-
1. If no mechanism is applied, lower priority schedules
will get CPU on Friday morning (that’s the holiday)
2. If mechanism applied, lower priority schedules will
be swapped away by the CPU- those that did not get
a chance for a specific period
 IBM 7094 was shut down in 1973… during theIBM 7094 was shut down in 1973… during the
shut down, MIT found a lower prioritizedshut down, MIT found a lower prioritized
process still ignored that was submitted in 1967!process still ignored that was submitted in 1967!
Rushdi Shams, Dept of CSE, KUET 24
Priority Scheduling: Aging
Technique to increase the priority of the processes
If priorities are ranged from 0 to 127 (127 is the highest
priority), then we can increase the priority of a process
for every 15 minutes.
The lowest prioritized process will now take no more
than 32 hours to get the CPU! 
Rushdi Shams, Dept of CSE, KUET 25
Round-Robin (RR) Scheduling
Similar to FCFS but pre-emption is added to switch
between processes
A smaller unit of time called time quantum (or time
slice) is defined generally from 10 to 100 ms.
The ready queue is treated as circular queue
Scheduler goes around the ready queue, allots CPU to
each process for a time interval of up to 1 time
quantum
Rushdi Shams, Dept of CSE, KUET 26
Round-Robin (RR) Scheduling
We need to treat the ready queue as FIFO
New processes are added at the end of the queue.
The CPU scheduler picks the first process from the
queue, sets a timer to interrupt the process after 1
time quantum and dispatches the process
Rushdi Shams, Dept of CSE, KUET 27
RR Scheduling
2 things may happen-
The process may have a CPU burst less than time
quantum- the process will release the CPU
voluntarily.
CPU burst of the process is longer than time
quantum-the process will be put at the end of the
queue.
Rushdi Shams, Dept of CSE, KUET 28
RR Scheduling
Time quantum is of 4 ms
Average waiting time: ((10-4)+4+7)/3 = 5.66 ms
Typically, higher average turnaround than SJF, but
better response
Rushdi Shams, Dept of CSE, KUET 29
RR Scheduling
The performance heavily depends on the size of time
quantum
If the time quantum is very large, at one extreme, it
would be similar to FCFS
If the time quantum is very small, the RR approach is
called processor sharing- as it seems every process has
its own CPU
Smaller time quantum requires more context
switching.
Rushdi Shams, Dept of CSE, KUET 30
Context switch with Quantum
Rushdi Shams, Dept of CSE, KUET 31
Turnaround time with Quantum
Rushdi Shams, Dept of CSE, KUET 32
80% of the CPU bursts
should be shorter than the
time quantum

Mais conteúdo relacionado

Mais procurados

cpu scheduling by shivam singh
cpu scheduling by shivam singhcpu scheduling by shivam singh
cpu scheduling by shivam singh
shivam71291
 
OS - CPU Scheduling
OS - CPU SchedulingOS - CPU Scheduling
OS - CPU Scheduling
vinay arora
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
Nagarajan
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 

Mais procurados (20)

5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
scheduling algorithm
scheduling algorithmscheduling algorithm
scheduling algorithm
 
Processor / CPU Scheduling
Processor / CPU SchedulingProcessor / CPU Scheduling
Processor / CPU Scheduling
 
Sa by shekhar
Sa by shekharSa by shekhar
Sa by shekhar
 
OSCh6
OSCh6OSCh6
OSCh6
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.
 
Ch05
Ch05Ch05
Ch05
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
cpu scheduling by shivam singh
cpu scheduling by shivam singhcpu scheduling by shivam singh
cpu scheduling by shivam singh
 
Scheduling algo(by HJ)
Scheduling algo(by HJ)Scheduling algo(by HJ)
Scheduling algo(by HJ)
 
PPT CPU
PPT CPUPPT CPU
PPT CPU
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round RobinComparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
 
OS - CPU Scheduling
OS - CPU SchedulingOS - CPU Scheduling
OS - CPU Scheduling
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
CPU scheduling
CPU schedulingCPU scheduling
CPU scheduling
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
Chapter6
Chapter6Chapter6
Chapter6
 

Destaque

L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
Rushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
Rushdi Shams
 
L13 why software fails
L13  why software failsL13  why software fails
L13 why software fails
Rushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Rushdi Shams
 
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating SystemsLecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Rushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
Rushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
Rushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
Rushdi Shams
 

Destaque (16)

L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L13 why software fails
L13  why software failsL13  why software fails
L13 why software fails
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Weka
WekaWeka
Weka
 
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating SystemsLecture 7, 8, 9 and 10  Inter Process Communication (IPC) in Operating Systems
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 

Semelhante a Lecture 5, 6 and 7 cpu scheduling

Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
Yogesh Santhan
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
Ch6
Ch6Ch6
Ch6
C.U
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
tech2click
 

Semelhante a Lecture 5, 6 and 7 cpu scheduling (20)

Scheduling
SchedulingScheduling
Scheduling
 
Operating System Scheduling
Operating System SchedulingOperating System Scheduling
Operating System Scheduling
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
LM10,11,12 - CPU SCHEDULING algorithms and its processes
LM10,11,12 - CPU SCHEDULING algorithms and its processesLM10,11,12 - CPU SCHEDULING algorithms and its processes
LM10,11,12 - CPU SCHEDULING algorithms and its processes
 
Process management in os
Process management in osProcess management in os
Process management in os
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
CPU scheduling in Operating System Explanation
CPU scheduling in Operating System ExplanationCPU scheduling in Operating System Explanation
CPU scheduling in Operating System Explanation
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Ch6
Ch6Ch6
Ch6
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Operating System Sheduling
Operating System ShedulingOperating System Sheduling
Operating System Sheduling
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
 
Ch05 cpu-scheduling
Ch05 cpu-schedulingCh05 cpu-scheduling
Ch05 cpu-scheduling
 

Mais de Rushdi Shams

L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
Rushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
Rushdi Shams
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
Rushdi Shams
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
Rushdi Shams
 
Lecture 14,15 and 16 file systems
Lecture 14,15 and 16  file systemsLecture 14,15 and 16  file systems
Lecture 14,15 and 16 file systems
Rushdi Shams
 
Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
Rushdi Shams
 
Lecture 1 and 2 processes
Lecture 1 and 2  processesLecture 1 and 2  processes
Lecture 1 and 2 processes
Rushdi Shams
 
Lecture 3 and 4 threads
Lecture 3 and 4  threadsLecture 3 and 4  threads
Lecture 3 and 4 threads
Rushdi Shams
 
Distributed Database Management Systems (Distributed DBMS)
Distributed Database Management Systems (Distributed DBMS)Distributed Database Management Systems (Distributed DBMS)
Distributed Database Management Systems (Distributed DBMS)
Rushdi Shams
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
Rushdi Shams
 

Mais de Rushdi Shams (18)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
 
Lecture 14,15 and 16 file systems
Lecture 14,15 and 16  file systemsLecture 14,15 and 16  file systems
Lecture 14,15 and 16 file systems
 
Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
 
Lecture 1 and 2 processes
Lecture 1 and 2  processesLecture 1 and 2  processes
Lecture 1 and 2 processes
 
Lecture 3 and 4 threads
Lecture 3 and 4  threadsLecture 3 and 4  threads
Lecture 3 and 4 threads
 
Distributed Database Management Systems (Distributed DBMS)
Distributed Database Management Systems (Distributed DBMS)Distributed Database Management Systems (Distributed DBMS)
Distributed Database Management Systems (Distributed DBMS)
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Lecture 5, 6 and 7 cpu scheduling

  • 1. Rushdi Shams, Dept of CSE, KUET 1 Operating Systems CPU Scheduling Version 1.0
  • 2. Rushdi Shams, Dept of CSE, KUET 2 Basic Concepts The objective of multiprogramming is to run processes all time, keeping the CPU busy. Uniprocessing system is different. Only one process can run at a time- means processes have to wait until the CPU is free.
  • 3. Rushdi Shams, Dept of CSE, KUET 3 Basic Concepts A process is executed until the completion of an IO request The CPU then sits idle and all this waiting time is wasted With multiprogramming, we keep several processes in memory at one time. When one process has to wait, the OS takes the CPU away from that process and gives the CPU to another process
  • 4. Rushdi Shams, Dept of CSE, KUET 4 Basic Concepts Almost all computer resources are scheduled before use. The CPU is one of the primary resources. Thus, its scheduling is central to operating systems
  • 5. Rushdi Shams, Dept of CSE, KUET 5 CPU burst and IO burst
  • 6. Rushdi Shams, Dept of CSE, KUET 6 CPU Scheduler  Selects from 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  Scheduling under 1 and 4 is nonpreemptive  All other scheduling is preemptive
  • 7. Rushdi Shams, Dept of CSE, KUET 7 CPU Scheduler In case of Non-preemptive scheduling, the process does not release the CPU unless it is finished (or terminated) or going to the waiting state.
  • 8. Rushdi Shams, Dept of CSE, KUET 8 Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context 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
  • 9. Rushdi Shams, Dept of CSE, KUET 9 Scheduling Criteria CPU utilization How much of the CPU is in operation, how much of it is utilized to serve processes. Measured in Percentage Should be maximized
  • 10. Rushdi Shams, Dept of CSE, KUET 10 Scheduling Criteria Throughput Number of processes executed and served per unit time. Measured in process per unit time Should be maximized
  • 11. Rushdi Shams, Dept of CSE, KUET 11 Scheduling Criteria Turnaround time Amount of time to execute a particular process Interval between the submission of the process and its completion Should be minimized
  • 12. Rushdi Shams, Dept of CSE, KUET 12 Scheduling Criteria Waiting time amount of time a process has been waiting in the ready queue Should be minimized
  • 13. Rushdi Shams, Dept of CSE, KUET 13 Scheduling Criteria 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) Should be minimized
  • 14. Rushdi Shams, Dept of CSE, KUET 14 First Come, First Served (FCFS) The simplest CPU Scheduling algorithm The process that requests CPU first is allocated the CPU first Easily managed with a FIFO queue
  • 15. Rushdi Shams, Dept of CSE, KUET 15 FCFS Proces 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 300
  • 16. Rushdi Shams, Dept of CSE, KUET 16 FCFS Proces Burst Time P1 24 P2 3 P3 3 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 P1P3P2 63 300
  • 17. Rushdi Shams, Dept of CSE, KUET 17 Shortest Job First (SJF)  Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time  Two schemes:  non-preemptive – 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 also called Shortest-Remaining-Time-First (SRTF)  SJF is optimal – gives minimum average waiting time for a given set of processes
  • 18. Rushdi Shams, Dept of CSE, KUET 18 SJF 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 P1 P3 P2 73 160 P4 8 12
  • 19. Rushdi Shams, Dept of CSE, KUET 19 SRTF 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 P3P2 42 110 P4 5 7 P2 P1 16
  • 20. Rushdi Shams, Dept of CSE, KUET 20 Priority Scheduling The SJF Algorithm is special case of Priority Scheduling A priority is associated with each process and the CPU is given to the process with higher priority If processes have equal priority, FCFS is followed SJF is priority algorithm where priority p = inverse of CPU burst Priorities are generally some fixed range of numbers such as 0 to 7 or 0 to 4,095
  • 21. Rushdi Shams, Dept of CSE, KUET 21 Priority Scheduling However, there is no agreement on the highest priority- if it would be 0 or 4,095 Priorities can be external or internal Internal priorities are number of files required to execute the process, its memory usage, resources required, time to compute, etc. External priorities are set by outside computer- mainly by human based on the choice of process, economical factors, etc.
  • 22. Rushdi Shams, Dept of CSE, KUET 22 Priority Scheduling The Average Waiting Time is (6+0+16+18+1)/5=8.2 ms
  • 23. Rushdi Shams, Dept of CSE, KUET 23 Priority Scheduling: Starvation  Higher priority schedules prohibits lower priority schedules for getting the CPU  There are two possibilities- 1. If no mechanism is applied, lower priority schedules will get CPU on Friday morning (that’s the holiday) 2. If mechanism applied, lower priority schedules will be swapped away by the CPU- those that did not get a chance for a specific period  IBM 7094 was shut down in 1973… during theIBM 7094 was shut down in 1973… during the shut down, MIT found a lower prioritizedshut down, MIT found a lower prioritized process still ignored that was submitted in 1967!process still ignored that was submitted in 1967!
  • 24. Rushdi Shams, Dept of CSE, KUET 24 Priority Scheduling: Aging Technique to increase the priority of the processes If priorities are ranged from 0 to 127 (127 is the highest priority), then we can increase the priority of a process for every 15 minutes. The lowest prioritized process will now take no more than 32 hours to get the CPU! 
  • 25. Rushdi Shams, Dept of CSE, KUET 25 Round-Robin (RR) Scheduling Similar to FCFS but pre-emption is added to switch between processes A smaller unit of time called time quantum (or time slice) is defined generally from 10 to 100 ms. The ready queue is treated as circular queue Scheduler goes around the ready queue, allots CPU to each process for a time interval of up to 1 time quantum
  • 26. Rushdi Shams, Dept of CSE, KUET 26 Round-Robin (RR) Scheduling We need to treat the ready queue as FIFO New processes are added at the end of the queue. The CPU scheduler picks the first process from the queue, sets a timer to interrupt the process after 1 time quantum and dispatches the process
  • 27. Rushdi Shams, Dept of CSE, KUET 27 RR Scheduling 2 things may happen- The process may have a CPU burst less than time quantum- the process will release the CPU voluntarily. CPU burst of the process is longer than time quantum-the process will be put at the end of the queue.
  • 28. Rushdi Shams, Dept of CSE, KUET 28 RR Scheduling Time quantum is of 4 ms Average waiting time: ((10-4)+4+7)/3 = 5.66 ms Typically, higher average turnaround than SJF, but better response
  • 29. Rushdi Shams, Dept of CSE, KUET 29 RR Scheduling The performance heavily depends on the size of time quantum If the time quantum is very large, at one extreme, it would be similar to FCFS If the time quantum is very small, the RR approach is called processor sharing- as it seems every process has its own CPU Smaller time quantum requires more context switching.
  • 30. Rushdi Shams, Dept of CSE, KUET 30 Context switch with Quantum
  • 31. Rushdi Shams, Dept of CSE, KUET 31 Turnaround time with Quantum
  • 32. Rushdi Shams, Dept of CSE, KUET 32 80% of the CPU bursts should be shorter than the time quantum