SlideShare a Scribd company logo
PROCESS
SCHEDULING
Sunawar Khan
MS(CS)
IIUI
Reference:-
After Reading This Topic. . .
Goals of
processor
scheduling.
Preemptive
vs. Non
preemptive
scheduling.
Role of
priorities in
scheduling.
Scheduling
criteria.
Common
scheduling
algorithms.
Reference:-
What is Process Scheduling?
Assignment of Processor to process to accomplish the work
When process should be assigned to which process is Process Scheduling
When more than one process is runnable, UPU must decide priority
Part of OS concerned with this decision is called Scheduler.
To solve this problem with different algorithm is called Scheduling Algorithm
http://www.cs.kent.edu/~rmuhamma/
Reference:-
Basic Concept
■ Maximum CPU utilization obtained
with multiprogramming
■ CPU–I/O Burst Cycle – Process
execution consists of a cycle of CPU
execution and I/O wait
■ CPU burst followed by I/O burst
■ CPU burst distribution is of main
concern
Silberchatz, Galvin and Gagne Operating System, 9th Edition
Reference:-
Policy To Process Scheduling
Decides which process runs at given time
Different schedulers goals Maximize throughput
Minimize latency
Prevent indefinite postponement
Complete process by given deadline
Maximize processor utilization
http://www.cs.kent.edu/~rmuhamma/
Reference:-
What the Scheduler try to achieve
•Maximize throughput
•Response Time
•Minimize resource utilization
•Avoid indefinite postponement
•Enforce priorities
•Minimize overhead
•Ensure predictability
•Policy Enforcement
Different objectives depending on system
Deitel & Deitel, Operating System
Reference:-
General Goals
Goals
Fairness Predictability Scalability
http://www.cs.kent.edu/~rmuhamma/
Reference:-
Scheduling Levels
High-level
scheduling
•Determines which jobs can compete for resources
•Controls number of processes in system at one time
Intermediate-
level
scheduling
•Determines which processes can compete for processors
•Responds to fluctuations in system load
Low-level
scheduling
•Assigns priorities
•Assigns processors to processes
Deitel & Deitel, Operating System
Reference:-
Scheduling Levels
Deitel & Deitel, Operating System
Reference:-
Preemptive vs. Nonpreemptive Scheduling
Preemptive
processes
Can be removed from their current processor
Can lead to improved response times
Important for interactive environments
Preempted processes remain in memory
Nonpreemptive
processes
Run until completion or until they yield control of a
processor
Unimportant processes can block important ones
indefinitely
http://www.cs.kent.edu/~rmuhamma/
Reference:-
CPU Scheduler
 Short-term scheduler selects from among the processes in ready queue, and
allocates the CPU to one of them
 Queue may be ordered in various ways
 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
 Consider access to shared data
 Consider preemption while in kernel mode
 Consider interrupts occurring during crucial OS activities
Silberchatz, Galvin and Gagne Operating System, 9th Edition
Reference:-
Scheduling Criteria
■ CPU utilization – keep the CPU as busy as possible
■ Throughput – # 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)
Silberchatz, Galvin and Gagne Operating System, 9th Edition
Reference:-
Scheduling Algorithm Optimization Criteria
■ Max CPU utilization
■ Max throughput
■ Min turnaround time
■ Min waiting time
■ Min response time
Silberchatz, Galvin and Gagne Operating System, 9th Edition
Reference:-14
Scheduling Algorithms
Scheduling
algorithms
Decide when and for how long each
process runs
Make choices about Preemptibility
Priority
Running time
Run-time-to-completion
fairness
Reference:-
First-In-First-Out (FIFO) Scheduling
FIFO
scheduling
•Simplest scheme
•Processes dispatched according to
arrival time
•Nonpreemptible
•Rarely used as primary scheduling
algorithm
Reference:-
FIFO
Process Burst Time
P1 24
P2 3
P3 3
■ Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
■ Waiting time for P1 = 0; P2 = 24; P3 = 27
■ Average waiting time: (0 + 24 + 27)/3 = 17
P P P1 2 3
0 24 3027
Reference:-
FIFO (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
– Consider one CPU-bound and many I/O-bound processes
P1
0 3 6 30
P2
P3
Reference:-
Round-Robin (RR) Scheduling
■ Round-robin scheduling
– Based on FIFO
– Processes run only for a limited amount of time called a time
slice or quantum
– Preemptible
– Requires the system to maintain several processes in memory
to minimize overhead
– Often used as part of more complex algorithms
Reference:-
Round Robin(RR) Scheduling
■ Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds.
After this time has elapsed, the process is preempted and added to the end of the ready
queue.
■ If there are n processes in the ready queue and the time quantum is q, then each process
gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more
than (n-1)q time units.
■ Timer interrupts every quantum to schedule next process
■ Performance
– q large  FIFO
– q small  q must be large with respect to context switch, otherwise overhead is too
high
Reference:-
Round Robin(RR) Scheduling
Reference:-
Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3
P3 3
■ The Gantt chart is:
■ Typically, higher average turnaround than SJF, but better response
■ q should be large compared to context switch time
■ q usually 10ms to 100ms, context switch < 10 usec
P P P1 1 1
0 18 3026144 7 10 22
P2
P3
P1
P1
P1
Reference:-
Time Quantum and Context Switch Time
Reference:-
Turnaround Time Varies With The Time Quantum
80% of CPU bursts
should be shorter than q
Reference:-24
Round-Robin (RR) Scheduling
■ Selfish round-robin scheduling
– Increases priority as process ages
– Two queues
■ Active
■ Holding
– Favors older processes to avoids unreasonable
delays
Reference:-25
Round-Robin (RR) Scheduling
■ Quantum size
– Determines response time to interactive requests
– Very large quantum size
■ Processes run for long periods
■ Degenerates to FIFO
– Very small quantum size
■ System spends more time context switching than running processes
– Middle-ground
■ Long enough for interactive processes to issue I/O request
■ Batch processes still get majority of processor time
Reference:-
Shortest-Process-First (SPF) Scheduling
■ Scheduler selects process with smallest time to finish
– Lower average wait time than FIFO
■ Reduces the number of waiting processes
– Potentially large variance in wait times
– Nonpreemptive
■ Results in slow response times to arriving interactive requests
– Relies on estimates of time-to-completion
■ Can be inaccurate or falsified
– Unsuitable for use in modern interactive systems
Reference:-
Shortest-Process-First (SPF) Scheduling
■ Associate with each process the length of its next CPU
burst
– Use these lengths to schedule the process with the
shortest time
■ SJF is optimal – gives minimum average waiting time for a
given set of processes
– The difficulty is knowing the length of the next CPU
request
– Could ask the user
Reference:-
Example of SJF
ProcessArriva l Time Burst Time
P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3
■ SJF scheduling chart
■ Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
P3
0 3 24
P4
P1
169
P2
Reference:-
Determining Length of Next CPU Burst
■ Can only estimate the length – should be similar to the previous one
– Then pick process with shortest predicted next CPU burst
■ Can be done by using the length of previous CPU bursts, using
exponential averaging
■ Commonly, α set to ½
■ Preemptive version called shortest-remaining-time-first
:Define4.
10,3.
burstCPUnexttheforvaluepredicted2.
burstCPUoflengthactual1.





 1n
th
n nt
  .11 nnn t  
Reference:-
Prediction of the Length of the Next CPU Burst
Reference:-
Examples of Exponential Averaging
■  =0
– n+1 = n
– Recent history does not count
■  =1
– n+1 =  tn
– Only the actual last CPU burst counts
■ If we expand the formula, we get:
n+1 =  tn+(1 - ) tn -1 + …
+(1 -  )j  tn -j + …
+(1 -  )n +1 0
■ Since both  and (1 - ) are less than or equal to 1, each successive term has less
weight than its predecessor
Reference:-
Example of Shortest-remaining-time-first
■ Now we add the concepts of varying arrival times and preemption to the analysis
ProcessAarri Arrival TimeT Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
■ Preemptive SJF Gantt Chart
■ Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec
P4
0 1 26
P1
P2
10
P3
P1
5 17
Reference:-
Multilevel Queue
■ Ready queue is partitioned into separate queues, eg:
– foreground (interactive)
– background (batch)
■ Process permanently in a given queue
■ Each queue has its own scheduling algorithm:
– foreground – RR
– background – FCFS
■ Scheduling must be done between the queues:
– Fixed priority scheduling; (i.e., serve all from foreground then from background).
Possibility of starvation.
– Time slice – each queue gets a certain amount of CPU time which it can schedule
amongst its processes; i.e., 80% to foreground in RR
– 20% to background in FCFS
Reference:-34
Multilevel Feedback Queues
■ Different processes have different needs
– Short I/O-bound interactive processes should generally run before
processor-bound batch processes
– Behavior patterns not immediately obvious to the scheduler
■ Multilevel feedback queues
– Arriving processes enter the highest-level queue and execute with higher
priority than processes in lower queues
– Long processes repeatedly descend into lower levels
■ Gives short processes and I/O-bound processes higher priority
■ Long processes will run when short and I/O-bound processes terminate
– Processes in each queue are serviced using round-robin
■ Process entering a higher-level queue preempt running processes
Reference:-35
Multilevel Feedback Queues
■ Algorithm must respond to changes in environment
– Move processes to different queues as they alternate between
interactive and batch behavior
■ Example of an adaptive mechanism
– Adaptive mechanisms incur overhead that often is offset by
increased sensitivity to process behavior
Reference:-
Multilevel Queue Scheduling
Reference:-
Multi Level Queue Scheduling
Reference:-
Multilevel Feedback Queue
■ A process can move between the various queues; aging can be
implemented this way
■ Multilevel-feedback-queue scheduler defined by the following
parameters:
– number of queues
– scheduling algorithms for each queue
– method used to determine when to upgrade a process
– method used to determine when to demote a process
– method used to determine which queue a process will enter
when that process needs service
Reference:-
Example of Multilevel Feedback Queue
■ Three queues:
– Q0 – RR with time quantum 8 milliseconds
– Q1 – RR time quantum 16 milliseconds
– Q2 – FCFS
■ Scheduling
– A new job enters queue Q0 which is served
FCFS
■ When it gains CPU, job receives 8
milliseconds
■ If it does not finish in 8
milliseconds, job is moved to queue
Q1
– At Q1 job is again served FCFS and
receives 16 additional milliseconds
■ If it still does not complete, it is
preempted and moved to queue Q2

More Related Content

PPT
Chapter 2 Operating System Structures.ppt
PPTX
Operating Systems: Process Scheduling
PPTX
Multiprocessor architecture
PPT
Window scheduling algorithm
PDF
Operating System-Ch8 memory management
PDF
Parallel programming model, language and compiler in ACA.
PPTX
parallel language and compiler
PPT
Ch6 CPU Scheduling galvin
Chapter 2 Operating System Structures.ppt
Operating Systems: Process Scheduling
Multiprocessor architecture
Window scheduling algorithm
Operating System-Ch8 memory management
Parallel programming model, language and compiler in ACA.
parallel language and compiler
Ch6 CPU Scheduling galvin

What's hot (20)

PPTX
Superscalar processor
PPTX
PRESCRIPTIVE PROCESS MODEL(SOFTWARE ENGINEERING)
PPTX
14- Process Synchronization.pptx
PPTX
First Come First Serve
PDF
5 process synchronization
PDF
P code
PPT
Process Scheduling
PPT
Scheduling algorithms
PDF
8. mutual exclusion in Distributed Operating Systems
PPTX
Distributed DBMS - Unit 9 - Distributed Deadlock & Recovery
PPT
Process threads operating system.
PDF
Ch4 memory management
PPTX
Dining philosopher problem operating system
PDF
2- THE CHANGING NATURE OF SOFTWARE.pdf
PPTX
CPU Scheduling in OS Presentation
PPTX
Computing Environment
PPTX
Page replacement algorithms
PPTX
Cpu scheduling in operating System.
PPT
5. spooling and buffering
PDF
Process scheduling (CPU Scheduling)
Superscalar processor
PRESCRIPTIVE PROCESS MODEL(SOFTWARE ENGINEERING)
14- Process Synchronization.pptx
First Come First Serve
5 process synchronization
P code
Process Scheduling
Scheduling algorithms
8. mutual exclusion in Distributed Operating Systems
Distributed DBMS - Unit 9 - Distributed Deadlock & Recovery
Process threads operating system.
Ch4 memory management
Dining philosopher problem operating system
2- THE CHANGING NATURE OF SOFTWARE.pdf
CPU Scheduling in OS Presentation
Computing Environment
Page replacement algorithms
Cpu scheduling in operating System.
5. spooling and buffering
Process scheduling (CPU Scheduling)
Ad

Viewers also liked (11)

PPTX
Process scheduling
PDF
5 Process Scheduling
PPT
Os Threads
PPTX
Threads (operating System)
PPSX
Process scheduling
PPT
Operating System-Threads-Galvin
PPT
Inter process communication
PDF
Process Scheduling
PPT
Interprocess Communication
PDF
Inter process communication
PDF
Inter Process Communication
Process scheduling
5 Process Scheduling
Os Threads
Threads (operating System)
Process scheduling
Operating System-Threads-Galvin
Inter process communication
Process Scheduling
Interprocess Communication
Inter process communication
Inter Process Communication
Ad

Similar to Process Scheduling (20)

PPT
OS-operating systems- ch05 (CPU Scheduling) ...
PPTX
Operating systems - Processes Scheduling
PPT
operating system Scheduling process unit 3.ppt
PPT
Process Scheduling in Ope Spptystems rating
PPT
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
PPTX
Chapter 3 - Operating System Scheduling.pptx
PPTX
Cpu_sheduling.pptx
PDF
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
PPT
Cpu scheduling
PDF
OS Process Chapter 3.pdf
PPTX
Operating Systems - CPU Scheduling Process
PPT
Operating System Scheduling
PPT
Ch05 cpu-scheduling
PPTX
3Chapter Three- CPU Scheduling this is the best.pptx
PDF
CH06.pdf
PDF
ch5_CPU Scheduling_part1.pdf
DOCX
UNIT II - CPU SCHEDULING.docx
PPTX
CPU Scheduling
PPTX
Preemptive process example.pptx
PPT
ch_scheduling (1).ppt
OS-operating systems- ch05 (CPU Scheduling) ...
Operating systems - Processes Scheduling
operating system Scheduling process unit 3.ppt
Process Scheduling in Ope Spptystems rating
ch6- CPU scheduling https://www.slideshare.net/slideshow/operating-system-18-...
Chapter 3 - Operating System Scheduling.pptx
Cpu_sheduling.pptx
cpu scheduling.pdfoieheoirwuojorkjp;ooooo
Cpu scheduling
OS Process Chapter 3.pdf
Operating Systems - CPU Scheduling Process
Operating System Scheduling
Ch05 cpu-scheduling
3Chapter Three- CPU Scheduling this is the best.pptx
CH06.pdf
ch5_CPU Scheduling_part1.pdf
UNIT II - CPU SCHEDULING.docx
CPU Scheduling
Preemptive process example.pptx
ch_scheduling (1).ppt

More from International Islamic University (20)

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
01-Introduction-to-Information-Management.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Business Ethics Teaching Materials for college
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Pre independence Education in Inndia.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Types and Its function , kingdom of life
01-Introduction-to-Information-Management.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Business Ethics Teaching Materials for college
Renaissance Architecture: A Journey from Faith to Humanism
Pre independence Education in Inndia.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Insiders guide to clinical Medicine.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
TR - Agricultural Crops Production NC III.pdf
Microbial diseases, their pathogenesis and prophylaxis
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Process Scheduling

  • 2. Reference:- After Reading This Topic. . . Goals of processor scheduling. Preemptive vs. Non preemptive scheduling. Role of priorities in scheduling. Scheduling criteria. Common scheduling algorithms.
  • 3. Reference:- What is Process Scheduling? Assignment of Processor to process to accomplish the work When process should be assigned to which process is Process Scheduling When more than one process is runnable, UPU must decide priority Part of OS concerned with this decision is called Scheduler. To solve this problem with different algorithm is called Scheduling Algorithm http://www.cs.kent.edu/~rmuhamma/
  • 4. Reference:- Basic Concept ■ Maximum CPU utilization obtained with multiprogramming ■ CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait ■ CPU burst followed by I/O burst ■ CPU burst distribution is of main concern Silberchatz, Galvin and Gagne Operating System, 9th Edition
  • 5. Reference:- Policy To Process Scheduling Decides which process runs at given time Different schedulers goals Maximize throughput Minimize latency Prevent indefinite postponement Complete process by given deadline Maximize processor utilization http://www.cs.kent.edu/~rmuhamma/
  • 6. Reference:- What the Scheduler try to achieve •Maximize throughput •Response Time •Minimize resource utilization •Avoid indefinite postponement •Enforce priorities •Minimize overhead •Ensure predictability •Policy Enforcement Different objectives depending on system Deitel & Deitel, Operating System
  • 7. Reference:- General Goals Goals Fairness Predictability Scalability http://www.cs.kent.edu/~rmuhamma/
  • 8. Reference:- Scheduling Levels High-level scheduling •Determines which jobs can compete for resources •Controls number of processes in system at one time Intermediate- level scheduling •Determines which processes can compete for processors •Responds to fluctuations in system load Low-level scheduling •Assigns priorities •Assigns processors to processes Deitel & Deitel, Operating System
  • 9. Reference:- Scheduling Levels Deitel & Deitel, Operating System
  • 10. Reference:- Preemptive vs. Nonpreemptive Scheduling Preemptive processes Can be removed from their current processor Can lead to improved response times Important for interactive environments Preempted processes remain in memory Nonpreemptive processes Run until completion or until they yield control of a processor Unimportant processes can block important ones indefinitely http://www.cs.kent.edu/~rmuhamma/
  • 11. Reference:- CPU Scheduler  Short-term scheduler selects from among the processes in ready queue, and allocates the CPU to one of them  Queue may be ordered in various ways  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  Consider access to shared data  Consider preemption while in kernel mode  Consider interrupts occurring during crucial OS activities Silberchatz, Galvin and Gagne Operating System, 9th Edition
  • 12. Reference:- Scheduling Criteria ■ CPU utilization – keep the CPU as busy as possible ■ Throughput – # 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) Silberchatz, Galvin and Gagne Operating System, 9th Edition
  • 13. Reference:- Scheduling Algorithm Optimization Criteria ■ Max CPU utilization ■ Max throughput ■ Min turnaround time ■ Min waiting time ■ Min response time Silberchatz, Galvin and Gagne Operating System, 9th Edition
  • 14. Reference:-14 Scheduling Algorithms Scheduling algorithms Decide when and for how long each process runs Make choices about Preemptibility Priority Running time Run-time-to-completion fairness
  • 15. Reference:- First-In-First-Out (FIFO) Scheduling FIFO scheduling •Simplest scheme •Processes dispatched according to arrival time •Nonpreemptible •Rarely used as primary scheduling algorithm
  • 16. Reference:- FIFO Process Burst Time P1 24 P2 3 P3 3 ■ Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: ■ Waiting time for P1 = 0; P2 = 24; P3 = 27 ■ Average waiting time: (0 + 24 + 27)/3 = 17 P P P1 2 3 0 24 3027
  • 17. Reference:- FIFO (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 – Consider one CPU-bound and many I/O-bound processes P1 0 3 6 30 P2 P3
  • 18. Reference:- Round-Robin (RR) Scheduling ■ Round-robin scheduling – Based on FIFO – Processes run only for a limited amount of time called a time slice or quantum – Preemptible – Requires the system to maintain several processes in memory to minimize overhead – Often used as part of more complex algorithms
  • 19. Reference:- Round Robin(RR) Scheduling ■ Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. ■ If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. ■ Timer interrupts every quantum to schedule next process ■ Performance – q large  FIFO – q small  q must be large with respect to context switch, otherwise overhead is too high
  • 21. Reference:- Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3 ■ The Gantt chart is: ■ Typically, higher average turnaround than SJF, but better response ■ q should be large compared to context switch time ■ q usually 10ms to 100ms, context switch < 10 usec P P P1 1 1 0 18 3026144 7 10 22 P2 P3 P1 P1 P1
  • 22. Reference:- Time Quantum and Context Switch Time
  • 23. Reference:- Turnaround Time Varies With The Time Quantum 80% of CPU bursts should be shorter than q
  • 24. Reference:-24 Round-Robin (RR) Scheduling ■ Selfish round-robin scheduling – Increases priority as process ages – Two queues ■ Active ■ Holding – Favors older processes to avoids unreasonable delays
  • 25. Reference:-25 Round-Robin (RR) Scheduling ■ Quantum size – Determines response time to interactive requests – Very large quantum size ■ Processes run for long periods ■ Degenerates to FIFO – Very small quantum size ■ System spends more time context switching than running processes – Middle-ground ■ Long enough for interactive processes to issue I/O request ■ Batch processes still get majority of processor time
  • 26. Reference:- Shortest-Process-First (SPF) Scheduling ■ Scheduler selects process with smallest time to finish – Lower average wait time than FIFO ■ Reduces the number of waiting processes – Potentially large variance in wait times – Nonpreemptive ■ Results in slow response times to arriving interactive requests – Relies on estimates of time-to-completion ■ Can be inaccurate or falsified – Unsuitable for use in modern interactive systems
  • 27. Reference:- Shortest-Process-First (SPF) Scheduling ■ Associate with each process the length of its next CPU burst – Use these lengths to schedule the process with the shortest time ■ SJF is optimal – gives minimum average waiting time for a given set of processes – The difficulty is knowing the length of the next CPU request – Could ask the user
  • 28. Reference:- Example of SJF ProcessArriva l Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3 ■ SJF scheduling chart ■ Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P3 0 3 24 P4 P1 169 P2
  • 29. Reference:- Determining Length of Next CPU Burst ■ Can only estimate the length – should be similar to the previous one – Then pick process with shortest predicted next CPU burst ■ Can be done by using the length of previous CPU bursts, using exponential averaging ■ Commonly, α set to ½ ■ Preemptive version called shortest-remaining-time-first :Define4. 10,3. burstCPUnexttheforvaluepredicted2. burstCPUoflengthactual1.       1n th n nt   .11 nnn t  
  • 30. Reference:- Prediction of the Length of the Next CPU Burst
  • 31. Reference:- Examples of Exponential Averaging ■  =0 – n+1 = n – Recent history does not count ■  =1 – n+1 =  tn – Only the actual last CPU burst counts ■ If we expand the formula, we get: n+1 =  tn+(1 - ) tn -1 + … +(1 -  )j  tn -j + … +(1 -  )n +1 0 ■ Since both  and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor
  • 32. Reference:- Example of Shortest-remaining-time-first ■ Now we add the concepts of varying arrival times and preemption to the analysis ProcessAarri Arrival TimeT Burst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5 ■ Preemptive SJF Gantt Chart ■ Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec P4 0 1 26 P1 P2 10 P3 P1 5 17
  • 33. Reference:- Multilevel Queue ■ Ready queue is partitioned into separate queues, eg: – foreground (interactive) – background (batch) ■ Process permanently in a given queue ■ Each queue has its own scheduling algorithm: – foreground – RR – background – FCFS ■ Scheduling must be done between the queues: – Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. – Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR – 20% to background in FCFS
  • 34. Reference:-34 Multilevel Feedback Queues ■ Different processes have different needs – Short I/O-bound interactive processes should generally run before processor-bound batch processes – Behavior patterns not immediately obvious to the scheduler ■ Multilevel feedback queues – Arriving processes enter the highest-level queue and execute with higher priority than processes in lower queues – Long processes repeatedly descend into lower levels ■ Gives short processes and I/O-bound processes higher priority ■ Long processes will run when short and I/O-bound processes terminate – Processes in each queue are serviced using round-robin ■ Process entering a higher-level queue preempt running processes
  • 35. Reference:-35 Multilevel Feedback Queues ■ Algorithm must respond to changes in environment – Move processes to different queues as they alternate between interactive and batch behavior ■ Example of an adaptive mechanism – Adaptive mechanisms incur overhead that often is offset by increased sensitivity to process behavior
  • 38. Reference:- Multilevel Feedback Queue ■ A process can move between the various queues; aging can be implemented this way ■ Multilevel-feedback-queue scheduler defined by the following parameters: – number of queues – scheduling algorithms for each queue – method used to determine when to upgrade a process – method used to determine when to demote a process – method used to determine which queue a process will enter when that process needs service
  • 39. Reference:- Example of Multilevel Feedback Queue ■ Three queues: – Q0 – RR with time quantum 8 milliseconds – Q1 – RR time quantum 16 milliseconds – Q2 – FCFS ■ Scheduling – A new job enters queue Q0 which is served FCFS ■ When it gains CPU, job receives 8 milliseconds ■ If it does not finish in 8 milliseconds, job is moved to queue Q1 – At Q1 job is again served FCFS and receives 16 additional milliseconds ■ If it still does not complete, it is preempted and moved to queue Q2