SlideShare a Scribd company logo
1 of 39
PROCESS SCHEDULING
PREVIOUS SESSION
1. Interprocess communication ( IPC )
2. Introduction to threads
3. Difference between threads and process
4. Multiprocessing vs multithreading
5. Multithreading challenges
• Watch my all previous OS sessions by visiting the playlist link in description
• Long session – timeline in description
• Subscribe for further updates
AGENDA
• IO Bound Process vs CPU Bound process
• Types of scheduling queues and schedulers
• Preemptive vs Nonpreemptive scheduling
• Role of Dispatcher
• Context Switch
• Scheduling criteria
• Scheduling algorithms ( FCFS, SJF, SRTF, Priority, Round Robin)
• Multilevel Queue Scheduling
INTERVIEW QUESTIONS
• What are different scheduling criterias
• Why is it important for the scheduler to distinguish I/0-bound
programs from CPU-bound programs?
• Difference between short-term, medium-term and long-term
scheduler
• What is context switch and a dispatcher?
• Difference between preemptive and nonpreemptive scheduling
• What is convoy effect in OS
• What is aging in OS?
• How to implement FCFS, SJF, SRTF, Priority or Round Robin
scheduling?
• What is starvation in process scheduling?
• Advantage and disadvantage of each process scheduling algorithm
• What is waiting time, turnaround time, response time in process
scheduling?
Need for process scheduling
• No choice
• Process terminates
• Process undergoes IO
• Multiple process waiting to run
• Faster response time
• Better CPU utlization
IO BOUND PROCESS
• Process spends most of it time waiting on IO
• Runs for a short time and the blocks on IO ( network, disk, keyboard )
• Example: Most GUI applications. Waiting for user interaction
• Text editors, terminals, process which does heavy read/write to disks
CPU BOUND PROCESS
• Most time is spent in executing code
• They run till they are preempted
While(1) {
// code
}
• Programs that does a lot of mathematical calculations like games
SOME PROCESS CAN BE BOTH
• Text Editor – waiting for input + spell check
• Games – waiting for input + render graphics
Detailed video: https://youtu.be/yKZrjI74VCk
SCHEDULERS
• Long-term scheduler
• Loads tasks from job queue ( disk ) to main memory ( Ready queue )
• Used in batch OS
• Doesn’t run very frequently
• Short-term scheduler
• Also called CPU scheduler
• Schedules process present in ready queue on CPU
• Runs very frequently – needs to be very fast
• Medium-term scheduler
• Memory manager
• Swapping in and out pages
Detailed video: https://youtu.be/ALSbJ2OodpQ
SCHEDULING QUEUES
• Job queue
• Tasks waiting on the disk
• Used in batch OS
• Long-term scheduler
• Ready queue
• Process waiting for the CPU are kept here
• PCB are stored here
• Short-term scheduler
• Device queue
• Each IO device has a waiting queue
Detailed video: https://youtu.be/xrUNRF5IWGs
CONTEXT SWITCH
CONTEXT SWITCH
• When one process is removed and another is scheduled, context
switch happens
• CPU registers value are saved to PCB of removed process
• Register values from PCB of scheduled process are loaded into CPU
registers
Detailed video: https://youtu.be/bId-MwXiDaI
DISPATCHER
• Gives control of the CPU to the process selected by short-term
scheduler
• Functions
• Context switch
• Switching to user mode
Detailed video - https://youtu.be/SydpWAOzmuE
NONPREEMPTIVE AND PREEMPTIVE
SCHEDULING
• In nonpreemptive scheduling, a process leaves the CPU voluntry
• Process terminates
• Process undergoes IO
• In preemptive scheduling, there are other reasons why process can
be kicked out from CPU
• Time slice of process expired
• A higher priority process entered the ready queue
• An interrupt ( hardware ) arrives on the CPU
Detailed video: https://youtu.be/K6N1eLbSu1o
SCHEDULING CRITERIA
• Cpu utilization – How much CPU is busy?
• Throughput – Number of processes completed per unit time
• Turnaround time(TAT) – Interval from time of submission of process
to completion of it
• Waiting time(WT) – Total time spent by a process in ready queue
• Response time(RT) – Interval from time of submission of process to
receiving of first response or time spent by process in ready queue for
the first time
OTHER IMPORTANT TERMS
• Arrival time (AT) – Time at which a process arrives in a ready queue
• Completion time (CT) – Time at which the process completes or
terminates
• Start time (ST) – Time at which a process starts its execution for the
first time
• Burst time (BT) – Total time spent on CPU or IO – CPU BT or IO BT
• By default, BT is CPU burst time
Detailed video - https://youtu.be/maosvQi-uWQ
FORMULAS
• TAT = CT – AT
• TAT = Total time spent in ready queue + total time spent on IO +. Total time
spent on the CPU
• TAT = WT + BT
• Do take care when you have IO
• WT = TAT – BT
• RT = ST – AT
• CPU Utilization = ((Total time – idle time)/total time)*100
• Throughput = Total process / Schedule length
• Schedule length = Max(CT) – Min(AT)
First come First Serve(FCFS) SCHEDULING
ALGORITHM
• The process which requests CPU first gets it first
• Schedule according to the Arrival time of the process
• FIFO implementation
• Nonpreemptive scheduling algorithm
MORE EXAMPLES FCFS FOR PRACTICE
• https://youtu.be/CHeAo9U2s_E
• https://youtu.be/_V23PCNnX9E
• https://youtu.be/pAwee32uRyo
ADVANTAGE AND DISADVANTAGE
Advantage
• Simple to implement
• No starvation
Disadvantages
• Waiting time can be very high
• Convoy effect – a process with large burst time increases waiting time for
all other processes behind it
• Favors CPU bound process over IO
• Less throughput and CPU utilization
Shortest-Job-First Scheduling (SJF)
• The process with least burst time gets CPU first
• Based on burst time
• If CPU burst time is same, use FCFS.
• Nonpreemptive scheduling
MORE EXAMPLES SJF FOR PRACTICE
• https://youtu.be/h79jrm2Jkuc
• https://youtu.be/B5gR_EC2IHM
Advantages and Disadvantages
Advantages
• Easy to implement
• Shorter jobs first – less waiting time
• Higher CPU utlilization and throughput than FCFS
Disadvantages
• Can lead to starvation
• Convoy effect possible here also
• Tough to implement ( predicting next CPU burst time )
Shortest Remaining Time First (SRTF)
• Similar to SJF
• Preemptive Scheduling
MORE EXAMPLES SRTF FOR PRACTICE
• https://youtu.be/6iG_c8I97rI
• https://youtu.be/kH4Uvr6qbTI
Advantages and Disadvantages
Advantages
• Shorter jobs first – less waiting time than FCFS and SJF
• Higher CPU utlilization and throughput than FCFS and SJF
• No convoy effect
Disadvantages
• Can lead to starvation
• Tough to implement ( predicting next CPU burst time )
Nonpreemptive priority scheduling
• Similar to SJF
• Here priority is provided explicitly
• In SJF, priority -> Burst time
• Priority -> 0-127
• Which is high priority and which is low?
• Nonpreemptive scheduling
• In case priority are same, follow FCFS
MORE EXAMPLES NONPREEMPTIVE PRIORITY
FOR PRACTICE
• https://youtu.be/8MCb5S_iSjU
• https://youtu.be/3MXQ4uP0XsA
• https://youtu.be/3lGhsUYMPDc
Preemptive Priority Scheduling
• Similar to SRTF
• Priority is explicitly mentioned here
• Preemptive scheduling
MORE EXAMPLES PREEMPTIVE PRIORITY FOR
PRACTICE
• https://youtu.be/VbFyvHSxftI
• https://youtu.be/SkpB0NDYS8E
Advantages and disadvantages
Advantage
• Easy to implement
• Good for critical process
Disadvantage
• Suffers from starvation (solved using aging technique )
• Deciding priority of the process
AGING TECHNIQUE
• A priority scheduling algorithm can leave some lowpriority processes
waiting indefinitely or starved
• Rumor has it that when they shut down the IBM 7094 at MIT in 1973,
they found a low-priority process that had been submitted in 1967
and had not yet been run.
• Aging is a technique of gradually increasing the priority of processes
that wait in the system for a long time. For example, if priorities range
from 127 (low) to 0 (high), we could decrease the priority of a waiting
process by 1 every 15 minutes.
ROUND ROBIN (RR) Scheduling algorithm
• Time sharing systems
• FCFS + preemption
• Time quantum or Time slice ( 1 to 100 ms )
• Implemented using FIFO queue
RR MORE EXAMPLES FOR PRACTICE
• https://youtu.be/kfYXMbc-Tok
• https://youtu.be/1d8r3M_tVXw
Advantages and disadvantages
Advantage
• Better response time
• No starvation
• No convoy effect
Disadvantages
• Average waiting time very high
• Time slice is low -> More context switches
• Time slice is high -> Becomes more like FCFS
MULTILEVEL QUEUE SCHEDULING
• Ready queue is divided into multiple queues
• Each queue has its own scheduling algorithm
• Scheduling algorithms among queues ( priority )
• Each queue has absolute priority over lower-priority queues. No process in
the batch queue, for example, could run unless the queues for system
processes, interactive processes, and interactive editing processes were all
empty. If an interactive editing process entered the ready queue while a
batch process was running, the batch process would be preempted.
• Another possibility is to time-slice among the queues. Here, each queue
gets a certain portion of the CPU time, which it can then schedule among
its various processes. For instance, in the foreground-background queue
example, the foreground queue can be given 80 percent of the CPU time
for RR scheduling among its processes, whereas the background queue
receives 20 percent of the CPU to give to its processes on an FCFS basis.
Multilevel Feedback Queue Scheduling
• In multilevel queue scheduling, processes are permanently assigned to a
queue
• This algorithm allows processes to move between queues.
• The idea is to separate processes according to the characteristics of their
CPU bursts.
• If a process uses too much CPU time, it will be moved to a lower-priority
queue. This scheme leaves I/O-bound and interactive processes in the
higher-priority queues.
• In addition, a process that waits too long in a lower-priority queue may be
moved to a higher-priority queue. This form of aging prevents starvation.
SOLUTIONS TO GIVEN PROBLEMS
• FCFS Example -> Question 1
• SJF AND SRTF -> Question 4
• Priority scheduling -> Question 7
• Round Robin -> Question 9
Link to questions and answers -
https://www.scribd.com/doc/121618986/Process-Scheduling-
problems

More Related Content

What's hot (20)

CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Scheduling
SchedulingScheduling
Scheduling
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Multilevel queue scheduling
Multilevel queue schedulingMultilevel queue scheduling
Multilevel queue scheduling
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
Part 1 - PROCESS CONCEPTS
Part 1  - PROCESS CONCEPTSPart 1  - PROCESS CONCEPTS
Part 1 - PROCESS CONCEPTS
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
cpu scheduling.pdf
cpu scheduling.pdfcpu scheduling.pdf
cpu scheduling.pdf
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
Priority scheduling algorithms
Priority scheduling algorithmsPriority scheduling algorithms
Priority scheduling algorithms
 
MULTILEVEL QUEUE SCHEDULING
MULTILEVEL QUEUE SCHEDULINGMULTILEVEL QUEUE SCHEDULING
MULTILEVEL QUEUE SCHEDULING
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 

Similar to Process Scheduling Algorithms | Interviews | Operating system

CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptxyashu23
 
UNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxUNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxansariparveen06
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling AlgorithmsTayba Farooqui
 
Operating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - SchedulingOperating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - SchedulingPeter Tröger
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingVaibhav Khanna
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptxDivyaKS18
 
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.Shreya Kumar
 
Lecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdfLecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdfHarika Pudugosula
 
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 processesmanideepakc
 
operating system (1).pdf
operating system (1).pdfoperating system (1).pdf
operating system (1).pdfAliyanAbbas1
 
Lecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptxLecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptxAmanuelmergia
 

Similar to Process Scheduling Algorithms | Interviews | Operating system (20)

CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptx
 
UNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxUNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptx
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Operating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - SchedulingOperating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - Scheduling
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of scheduling
 
ch_scheduling (1).ppt
ch_scheduling (1).pptch_scheduling (1).ppt
ch_scheduling (1).ppt
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptx
 
Osy ppt - Copy.pptx
Osy ppt - Copy.pptxOsy ppt - Copy.pptx
Osy ppt - Copy.pptx
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
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.
 
Lecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdfLecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdf
 
CPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdfCPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdf
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Operating system
Operating systemOperating system
Operating system
 
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
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
operating system (1).pdf
operating system (1).pdfoperating system (1).pdf
operating system (1).pdf
 
Lecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptxLecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptx
 
Section05 scheduling
Section05 schedulingSection05 scheduling
Section05 scheduling
 

More from Shivam Mitra

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE InterviewsShivam Mitra
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesShivam Mitra
 
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesPART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesShivam Mitra
 
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesPART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesShivam Mitra
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesShivam Mitra
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesShivam Mitra
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesShivam Mitra
 
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesPART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesShivam Mitra
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonShivam Mitra
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonShivam Mitra
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsShivam Mitra
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it WorksShivam Mitra
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackShivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock MarketShivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liabilityShivam Mitra
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scoresShivam Mitra
 

More from Shivam Mitra (16)

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
 
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesPART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
 
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesPART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With Examples
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With Examples
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
 
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesPART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With Examples
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn python
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to Lists
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it Works
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol Stack
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scores
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

Process Scheduling Algorithms | Interviews | Operating system

  • 2. PREVIOUS SESSION 1. Interprocess communication ( IPC ) 2. Introduction to threads 3. Difference between threads and process 4. Multiprocessing vs multithreading 5. Multithreading challenges • Watch my all previous OS sessions by visiting the playlist link in description • Long session – timeline in description • Subscribe for further updates
  • 3. AGENDA • IO Bound Process vs CPU Bound process • Types of scheduling queues and schedulers • Preemptive vs Nonpreemptive scheduling • Role of Dispatcher • Context Switch • Scheduling criteria • Scheduling algorithms ( FCFS, SJF, SRTF, Priority, Round Robin) • Multilevel Queue Scheduling
  • 4. INTERVIEW QUESTIONS • What are different scheduling criterias • Why is it important for the scheduler to distinguish I/0-bound programs from CPU-bound programs? • Difference between short-term, medium-term and long-term scheduler • What is context switch and a dispatcher? • Difference between preemptive and nonpreemptive scheduling • What is convoy effect in OS
  • 5. • What is aging in OS? • How to implement FCFS, SJF, SRTF, Priority or Round Robin scheduling? • What is starvation in process scheduling? • Advantage and disadvantage of each process scheduling algorithm • What is waiting time, turnaround time, response time in process scheduling?
  • 6. Need for process scheduling • No choice • Process terminates • Process undergoes IO • Multiple process waiting to run • Faster response time • Better CPU utlization
  • 7. IO BOUND PROCESS • Process spends most of it time waiting on IO • Runs for a short time and the blocks on IO ( network, disk, keyboard ) • Example: Most GUI applications. Waiting for user interaction • Text editors, terminals, process which does heavy read/write to disks
  • 8. CPU BOUND PROCESS • Most time is spent in executing code • They run till they are preempted While(1) { // code } • Programs that does a lot of mathematical calculations like games
  • 9. SOME PROCESS CAN BE BOTH • Text Editor – waiting for input + spell check • Games – waiting for input + render graphics Detailed video: https://youtu.be/yKZrjI74VCk
  • 10. SCHEDULERS • Long-term scheduler • Loads tasks from job queue ( disk ) to main memory ( Ready queue ) • Used in batch OS • Doesn’t run very frequently • Short-term scheduler • Also called CPU scheduler • Schedules process present in ready queue on CPU • Runs very frequently – needs to be very fast • Medium-term scheduler • Memory manager • Swapping in and out pages Detailed video: https://youtu.be/ALSbJ2OodpQ
  • 11. SCHEDULING QUEUES • Job queue • Tasks waiting on the disk • Used in batch OS • Long-term scheduler • Ready queue • Process waiting for the CPU are kept here • PCB are stored here • Short-term scheduler • Device queue • Each IO device has a waiting queue Detailed video: https://youtu.be/xrUNRF5IWGs
  • 12. CONTEXT SWITCH CONTEXT SWITCH • When one process is removed and another is scheduled, context switch happens • CPU registers value are saved to PCB of removed process • Register values from PCB of scheduled process are loaded into CPU registers Detailed video: https://youtu.be/bId-MwXiDaI
  • 13. DISPATCHER • Gives control of the CPU to the process selected by short-term scheduler • Functions • Context switch • Switching to user mode Detailed video - https://youtu.be/SydpWAOzmuE
  • 14. NONPREEMPTIVE AND PREEMPTIVE SCHEDULING • In nonpreemptive scheduling, a process leaves the CPU voluntry • Process terminates • Process undergoes IO • In preemptive scheduling, there are other reasons why process can be kicked out from CPU • Time slice of process expired • A higher priority process entered the ready queue • An interrupt ( hardware ) arrives on the CPU Detailed video: https://youtu.be/K6N1eLbSu1o
  • 15. SCHEDULING CRITERIA • Cpu utilization – How much CPU is busy? • Throughput – Number of processes completed per unit time • Turnaround time(TAT) – Interval from time of submission of process to completion of it • Waiting time(WT) – Total time spent by a process in ready queue • Response time(RT) – Interval from time of submission of process to receiving of first response or time spent by process in ready queue for the first time
  • 16. OTHER IMPORTANT TERMS • Arrival time (AT) – Time at which a process arrives in a ready queue • Completion time (CT) – Time at which the process completes or terminates • Start time (ST) – Time at which a process starts its execution for the first time • Burst time (BT) – Total time spent on CPU or IO – CPU BT or IO BT • By default, BT is CPU burst time Detailed video - https://youtu.be/maosvQi-uWQ
  • 17. FORMULAS • TAT = CT – AT • TAT = Total time spent in ready queue + total time spent on IO +. Total time spent on the CPU • TAT = WT + BT • Do take care when you have IO • WT = TAT – BT • RT = ST – AT • CPU Utilization = ((Total time – idle time)/total time)*100 • Throughput = Total process / Schedule length • Schedule length = Max(CT) – Min(AT)
  • 18. First come First Serve(FCFS) SCHEDULING ALGORITHM • The process which requests CPU first gets it first • Schedule according to the Arrival time of the process • FIFO implementation • Nonpreemptive scheduling algorithm
  • 19. MORE EXAMPLES FCFS FOR PRACTICE • https://youtu.be/CHeAo9U2s_E • https://youtu.be/_V23PCNnX9E • https://youtu.be/pAwee32uRyo
  • 20. ADVANTAGE AND DISADVANTAGE Advantage • Simple to implement • No starvation Disadvantages • Waiting time can be very high • Convoy effect – a process with large burst time increases waiting time for all other processes behind it • Favors CPU bound process over IO • Less throughput and CPU utilization
  • 21. Shortest-Job-First Scheduling (SJF) • The process with least burst time gets CPU first • Based on burst time • If CPU burst time is same, use FCFS. • Nonpreemptive scheduling
  • 22. MORE EXAMPLES SJF FOR PRACTICE • https://youtu.be/h79jrm2Jkuc • https://youtu.be/B5gR_EC2IHM
  • 23. Advantages and Disadvantages Advantages • Easy to implement • Shorter jobs first – less waiting time • Higher CPU utlilization and throughput than FCFS Disadvantages • Can lead to starvation • Convoy effect possible here also • Tough to implement ( predicting next CPU burst time )
  • 24. Shortest Remaining Time First (SRTF) • Similar to SJF • Preemptive Scheduling
  • 25. MORE EXAMPLES SRTF FOR PRACTICE • https://youtu.be/6iG_c8I97rI • https://youtu.be/kH4Uvr6qbTI
  • 26. Advantages and Disadvantages Advantages • Shorter jobs first – less waiting time than FCFS and SJF • Higher CPU utlilization and throughput than FCFS and SJF • No convoy effect Disadvantages • Can lead to starvation • Tough to implement ( predicting next CPU burst time )
  • 27. Nonpreemptive priority scheduling • Similar to SJF • Here priority is provided explicitly • In SJF, priority -> Burst time • Priority -> 0-127 • Which is high priority and which is low? • Nonpreemptive scheduling • In case priority are same, follow FCFS
  • 28. MORE EXAMPLES NONPREEMPTIVE PRIORITY FOR PRACTICE • https://youtu.be/8MCb5S_iSjU • https://youtu.be/3MXQ4uP0XsA • https://youtu.be/3lGhsUYMPDc
  • 29. Preemptive Priority Scheduling • Similar to SRTF • Priority is explicitly mentioned here • Preemptive scheduling
  • 30. MORE EXAMPLES PREEMPTIVE PRIORITY FOR PRACTICE • https://youtu.be/VbFyvHSxftI • https://youtu.be/SkpB0NDYS8E
  • 31. Advantages and disadvantages Advantage • Easy to implement • Good for critical process Disadvantage • Suffers from starvation (solved using aging technique ) • Deciding priority of the process
  • 32. AGING TECHNIQUE • A priority scheduling algorithm can leave some lowpriority processes waiting indefinitely or starved • Rumor has it that when they shut down the IBM 7094 at MIT in 1973, they found a low-priority process that had been submitted in 1967 and had not yet been run. • Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time. For example, if priorities range from 127 (low) to 0 (high), we could decrease the priority of a waiting process by 1 every 15 minutes.
  • 33. ROUND ROBIN (RR) Scheduling algorithm • Time sharing systems • FCFS + preemption • Time quantum or Time slice ( 1 to 100 ms ) • Implemented using FIFO queue
  • 34. RR MORE EXAMPLES FOR PRACTICE • https://youtu.be/kfYXMbc-Tok • https://youtu.be/1d8r3M_tVXw
  • 35. Advantages and disadvantages Advantage • Better response time • No starvation • No convoy effect Disadvantages • Average waiting time very high • Time slice is low -> More context switches • Time slice is high -> Becomes more like FCFS
  • 36. MULTILEVEL QUEUE SCHEDULING • Ready queue is divided into multiple queues • Each queue has its own scheduling algorithm • Scheduling algorithms among queues ( priority )
  • 37. • Each queue has absolute priority over lower-priority queues. No process in the batch queue, for example, could run unless the queues for system processes, interactive processes, and interactive editing processes were all empty. If an interactive editing process entered the ready queue while a batch process was running, the batch process would be preempted. • Another possibility is to time-slice among the queues. Here, each queue gets a certain portion of the CPU time, which it can then schedule among its various processes. For instance, in the foreground-background queue example, the foreground queue can be given 80 percent of the CPU time for RR scheduling among its processes, whereas the background queue receives 20 percent of the CPU to give to its processes on an FCFS basis.
  • 38. Multilevel Feedback Queue Scheduling • In multilevel queue scheduling, processes are permanently assigned to a queue • This algorithm allows processes to move between queues. • The idea is to separate processes according to the characteristics of their CPU bursts. • If a process uses too much CPU time, it will be moved to a lower-priority queue. This scheme leaves I/O-bound and interactive processes in the higher-priority queues. • In addition, a process that waits too long in a lower-priority queue may be moved to a higher-priority queue. This form of aging prevents starvation.
  • 39. SOLUTIONS TO GIVEN PROBLEMS • FCFS Example -> Question 1 • SJF AND SRTF -> Question 4 • Priority scheduling -> Question 7 • Round Robin -> Question 9 Link to questions and answers - https://www.scribd.com/doc/121618986/Process-Scheduling- problems