SlideShare a Scribd company logo
CPU/PROCESS SCHEDULING
Scheduling Techniques and examples
CPU Scheduling
CPU scheduling is the basis of multiprogrammed operating
systems. By switching the CPU among processes, the
operating system can make the computer more productive.
• In a single-processor system, only one process can run at a
time. Others must wait until the CPU is free and can be
rescheduled.
• The objective of multiprogramming is to have some process
running at all times, to maximize CPU utilization.
• The idea is relatively simple. A process is executed until it
must wait, typically for the completion of some I/O request. In
a simple computer system, the CPU then just sits idle. All this
waiting time is wasted; no useful work is accomplished.
2
CPU Scheduling
• With multiprogramming, we try to use this time productively.
Several processes are kept in memory at one time.
• When one process has to wait, the operating system takes the
CPU away from that process and gives the CPU to another
process. This pattern continues. Every time one process has
to wait, another process can take over use of the CPU.
3
CPU–I/O Burst Cycle
• 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
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
Dispatcher
• Dispatcher module gives control of the CPU to the process
selected by the short-term scheduler; this involves:
• switching context
• switching to user mode
• jumping to the proper location in the user program to restart that
program
• Dispatch latency – time it takes for the dispatcher to stop
one process and start another running
Scheduling Algorithms
Basic categories:
• Non-preemptive Mode: In this scheduling, a process
continues to execute until it terminates. The process
blocks itself to wait for I/O or by requesting some
operating system service.
• Preemptive Mode: The currently running process may
be interrupted and moved to the Ready state by the
operating system.
The decision to preempt may be due to:
 a new process arrives
 an interrupt occurs that places a Blocked process in the
Ready state
 periodically on the basis of a clock interrupt.
7
Scheduling Algorithms
(1) Pure Priority Scheduling Scheme
• Each process is assigned a priority.
• The scheduler always chooses a process of higher priority
over one of the lower priority.
• Multiple “ready queues” with priorities RQ0 > RQ1 > … >
RQn.
• Process is selected from the highest priority ready queue.
• Problem: Lower priority processes may suffer starvation,
when there is a steady supply of higher-priority ready
processes.
• Solution: Priority of a process can change with its age or
execution history.
8
Priority Scheduling (Simplified Queuing Diagram)
Processor
.
.
.
Release
Time-out
DispatchRQ0
Event-wait
Block Queue
Event
Occur
RQ1
RQn
Scheduling Algorithms
9
Admit
Example of Priority Scheduling
ProcessAarri Burst TimeT Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
• Priority scheduling Gantt Chart
• Average waiting time = 8.2 msec
1
0 1 19
P1
P2
16
P4
P3
6 18
PP2 P5
SchedulingAlgorithms
(2) First-Come, First-Served Scheme
• First-Come, First-Served (FCFS) scheme is also called
First-In, First-Out (FIFO) scheme.
• The dispatcher runs the processes at head of single ready
queue, new processes come in at the end of the queue.
• Non-Preemptive technique
• Shorter processes have to wait a lot while a long process is
executed by processor.
• FCFS tends to favor CPU-Bound processes over I/O-Bound
processes.
• FCFS is easier and faster but may result inefficient use of
processor and the I/O devices.
11
(2) First-Come, First-Served Scheme (con..)
• I/O-Bound Processes: Processes that perform lots of I/O
operations. Each I/O is followed by a short CPU burst.
• CPU-Bound Processes: Processes that perform lots of
computation and do little I/O. They tend to have long few
CPU bursts.
CPU burst: The amount of time the process uses the
processor before it is no longer ready. Types of CPU
bursts:
• long bursts -- process is CPU bound (i.e. array work)
• short bursts -- process I/O bound.
12
SchedulingAlgorithms
First- Come, First-Served (FCFS) Scheduling: Example
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
• Convoy effect - short process behind long process
• There is a convoy effect as all the other processes wait for the one big
process to get off the CPU. This effect results in lower CPU and device
utilization than might be possible if the shorter processes were allowed
to go first.
P P P1 2 3
0 24 3027
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order:
P2 , P3 , P1
The Gantt chart for the schedule is:
Waiting time for P1 = 6; P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Thus, the average waiting time under an FCFS policy is
generally not minimal and may vary substantially if the
processes’ CPU burst times vary greatly.
P1
0 3 6 30
P2
P3
SchedulingAlgorithms
(3) Round-Robin Scheme
The round-robin (RR) scheduling algorithm is designed especially for
time- sharing systems. It is similar to FCFS scheduling, but preemption is
added to enable the system to switch between processes.
• A small unit of time, called a time quantum or time slice, is
defined
• If a process’s CPU burst exceeds 1 time quantum, that process is
preempted and is put back in the ready queue.
• A clock-interrupt is generated at periodic intervals.
• When the interrupt occurs, the currently running process is
placed in the Ready queue
• Next process is selected on first-come, first-served basis.
• Also known as time-slicing or time-quantization, because
each process is given a slice / quantum of time
15
SchedulingAlgorithms
(3) Round-Robin Scheme (con…)
Length or time quantum/slice: Short vs. Long
• If the time quantum is very short, then short processes will
move through the system relatively quickly.
• However, there is processing overhead involved in handling
the clock interrupt and performing the dispatching function.
• Standard time quantum is slightly greater than the time
required for a typical interaction.
CPU-Bound vs. I/O-Bound Processes
• I/O-bound processes tend to receive an unfair portion of
processor time, which results in poor performance of I/O-
bound processes.
16
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
Time Quantum and Context Switch Time
The performance of the RR algorithm depends heavily on the size of the
time quantum. At one extreme, if the time quantum is extremely large,
the RR policy. In contrast, if the time quantum is extremely small (say, 1
millisecond), the RR approach can result in a large number of context
switches.
SchedulingAlgorithms
(4) Virtual Round-Robin Scheme
• Similar to Round Robin
• When a running process times out, it is returned to the Ready
queue.
• When a process is blocked for I/O, it joins an I/O queue.
• Auxiliary Queue based on FCFS is used to which processes
that are moved after being released from an I/O wait.
• Processes in the auxiliary queue get preference over those in
the main Ready queue.
• Superior to the Round-Robin in terms of fairness.
19
Queuing diagram for Virtual Round Robin Scheduler
Processor
Admit Release
Time-out
Dispatch
Ready Queue
Event 1 - wait
Block Queue 1
Event 1
Occur
Event 2 - wait
Block Queue 2
Event 2
Occur
Event n - wait
Block Queue n
Event n
Occur
Auxiliary Queue
Scheduling Algorithms
20
SchedulingAlgorithms
(5) Shortest Job First Scheme
• When the CPU is available, it is assigned to the process that has
the smallest next CPU burst.
• If the next CPU bursts of two processes are the same, FCFS
scheduling is used to break the tie.
• Note that a more appropriate term for this scheduling method would
be the shortest-next- CPU-burst algorithm, because scheduling
depends on the length of the next CPU burst of a process, rather
than its total length.
• Shortest Job First (SJF) is a non-preemptive policy
• The difficulty with SJF policy is the “need to know the
estimate time required for processing each process”.
• Short processes will jump to the head of the queue past
longer processes
21
Example of SJF
ProcessArriva l TimeBurst 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
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  
SchedulingAlgorithms
(6) Highest Response Ratio Next (HRRN)
• The response ratio is given by
RR = (w+s)/s
where
w = time spent waiting for the processor
s = expected service time
• Non-Preemptive scheme
• When the current process completes or is blocked, choose the ready
process with the largest value of RR.
• This approach is attractive, because it accounts for the age of the
process.
• Shorter jobs are favored (a small denominator yields a larger ratio),
aging without service increases the ratio.
• As with the shortest process next, the expected time must be
estimated before using the technique.
24
Scheduling Algorithms
(7) Feedback Scheme
• This scheme is based on the time spent by a process in
execution.
• Scheduling is done on a preemptive basis, and a dynamic
priority mechanism is used.
• When a process first enters the system, it is placed in RQ0
(high priority queue).
• When it returns to the Ready state after its first execution, it is
placed in RQ1 (lower priority queue).
• After each subsequent execution, it is demoted to the lower
priority queue.
• A shorter process will complete quickly, without migrating very
far down the hierarchy of Ready queues.
• A longer process will gradually drift downwards.
25
Scheduling Algorithms
(7) Feedback Scheme
• Thus newer, shorter processes are favored over older longer
processes.
• Last queue is treated with Round Robin technique, while other
are treated as FCFS
26
Processor
Admit
ReleaseDispatchRQ0
Processor
RQ1
Processor
RQn
. . .
Release
* Dotted lines shows a time sequence rather than a static transitions.
Scheduling Algorithms
(8) Fair-Share Scheduling (FFS) Scheme
• Preemptive technique
• The processes are divided into groups
• Each group is managed by certain scheme, mostly Round
Robin Scheme is used
• The turn take into account:
• The CPU usage of the group to which the process
belongs.
• The technique used to schedule a process of a group
(e.g. Round Robin, HRRN etc.)
• Used when there is a multiuser system
27
Consider the following set of processes that arrive at time
0, with the length of CPU-burst time given in milliseconds:
Process Burst-Time
P1 24
P2 3
P3 3
If we use a time quantum of 4 milliseconds, then find out
the average waiting time with Round Robin (RR).
Solution:
Average waiting time (RR, q = 4) = (6+4+7)/3 = 5.66
0 to 3 4 to 6 7 to 9 10 to 29
Round
Robin
(q = 4)
P1 P1
P2
P4
Scheduling Algorithms Examples
28
Scheduling Algorithms Examples
Consider the following set of processes, with the length of the CPU
burst time given in milliseconds (excluding the transition time):
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
The processes are assumed to have arrived in the order P1, P2, P3,
P3, P4, P5, all at time 0.
(a) Draw four Gantt charts illustrating the execution of these processes
using FCFS, SJF, a non-preemptive priority (a smaller priority number
implies a higher priority) and RR (quantum =1) scheduling.
(b) What is the turnaround time of each process for each of the
scheduling algorithm in part a?
(c) What is the waiting time of each process for each of the scheduling
algorithm in part a?
(d) Which of the schedules in part a, results in the minimal average
waiting time (over all processes)?
29
(a) Gantt Chart
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
FCFS
P1
P2
P3
P4
P5
SJF
P2
P4
P3
P5
P1
Non-Preemptive
Priority
P2
P5
P3
P1
P4
Round
Robin
P1 P1 P1 P1 P1 P1
P2
P3 P3
P4
P5 P5 P5 P5 P5
Scheduling Algorithms Examples
30
(b) Turnaround of each process & (c) Waiting time of
each process
(d) Minimal average waiting time
According to above example, SJF technique
results minimal average time of overall processes.
Scheduling Algorithms Examples
31
P1 P2 P3 P4 P5
FCFS
Turnaround 10 11 13 14 19
Waiting 0 10 11 13 14
SJF
Turnaround 19 1 4 2 9
Waiting 9 0 2 1 4
Non-preemptive
Priority
Turnaround 18 1 9 19 6
Waiting 9 0 6 18 1
Round Robin
Turnaround 19 2 7 4 14
Waiting 9 1 5 3 9
Scheduling Algorithms Examples
32
Suppose that the following processes arrive for execution at the times indicated. Each
process will run the listed amount of time. In answering the questions, use non-
preemptive scheduling and base all decisions on the information you have at the time of
the decision must be made.
Process Arrival Time Burst Time
P1 0.0 8
P2 0.4 4
P3 1.0 1
(a) What is the average turnaround time for these processes with the FCFS scheduling
algorithm?
(b) What is the average turnaround time of these processes for SJF scheduling
algorithm?
(c) The SJF algorithm is supposed to improve performance, but notice that we chose to
run process P1 at time 0 because we did not know that two shorter processes would
arrive soon. Compute what the average turnaround time will be, if the CPU is left idle for
the first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2
are waiting during this idle time, so their waiting time may increase. This algorithm could
be known as future-knowledge scheduling.
Solution:
Average turnaround time (Non-preemptive FCFS) = (8+12+13)/3 = 11
Average turnaround time (Non-preemptive SJF) = (8+9+13)/3 = 10
Average turnaround time (Non-preemptive+1 idle unit) = (1+6+14)/3 = 7

More Related Content

What's hot

Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
Dr. Loganathan R
 
Boolean expression org.
Boolean expression org.Boolean expression org.
Boolean expression org.
mshoaib15
 
Operations on Processes
Operations on ProcessesOperations on Processes
Operations on Processes
Navid Daneshvaran
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
MOHIT DADU
 
Time complexity
Time complexityTime complexity
Time complexity
Katang Isip
 
Performance of second order system
Performance of second order systemPerformance of second order system
Performance of second order system
Trupesh Rupareliya
 
Multiprocessor Scheduling
Multiprocessor SchedulingMultiprocessor Scheduling
Multiprocessor Scheduling
Khadija Saleem
 
Interactive os
Interactive osInteractive os
Interactive osmimie_ghaz
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
Meenakshi Paul
 
Lustre, RoCE, and MAN
Lustre, RoCE, and MANLustre, RoCE, and MAN
Lustre, RoCE, and MAN
inside-BigData.com
 
Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...
Shivam Mitra
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifomyrajendra
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
Khaled Sany
 
Control system mathematical modelling of a system
Control system mathematical modelling of a systemControl system mathematical modelling of a system
Control system mathematical modelling of a system
Nilesh Bhaskarrao Bahadure
 
Eceg 3201-dld-lec 12-synchronous_counter_design
Eceg 3201-dld-lec 12-synchronous_counter_designEceg 3201-dld-lec 12-synchronous_counter_design
Eceg 3201-dld-lec 12-synchronous_counter_designNebiyu Musie
 
Lecture 23 24-time_response
Lecture 23 24-time_responseLecture 23 24-time_response
Lecture 23 24-time_response
Syed Ali Raza Rizvi
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
Arnav Chowdhury
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating SystemsNitish Gulati
 

What's hot (20)

Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Boolean expression org.
Boolean expression org.Boolean expression org.
Boolean expression org.
 
Operations on Processes
Operations on ProcessesOperations on Processes
Operations on Processes
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Time complexity
Time complexityTime complexity
Time complexity
 
Performance of second order system
Performance of second order systemPerformance of second order system
Performance of second order system
 
Multiprocessor Scheduling
Multiprocessor SchedulingMultiprocessor Scheduling
Multiprocessor Scheduling
 
Interactive os
Interactive osInteractive os
Interactive os
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Lustre, RoCE, and MAN
Lustre, RoCE, and MANLustre, RoCE, and MAN
Lustre, RoCE, and MAN
 
Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...Process management in operating system | process states | PCB | FORK() | Zomb...
Process management in operating system | process states | PCB | FORK() | Zomb...
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
 
Control system mathematical modelling of a system
Control system mathematical modelling of a systemControl system mathematical modelling of a system
Control system mathematical modelling of a system
 
Eceg 3201-dld-lec 12-synchronous_counter_design
Eceg 3201-dld-lec 12-synchronous_counter_designEceg 3201-dld-lec 12-synchronous_counter_design
Eceg 3201-dld-lec 12-synchronous_counter_design
 
Lecture 23 24-time_response
Lecture 23 24-time_responseLecture 23 24-time_response
Lecture 23 24-time_response
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
 

Similar to Cpu scheduling

Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
Paurav Shah
 
ch_scheduling (1).ppt
ch_scheduling (1).pptch_scheduling (1).ppt
ch_scheduling (1).ppt
Farhanahmad540205
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
M. Abdullah Wasif
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
Kp Sharma
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
KeyreSebre
 
CPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdfCPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdf
Harika Pudugosula
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
Mukesh Chinta
 
Ch05 cpu-scheduling
Ch05 cpu-schedulingCh05 cpu-scheduling
Ch05 cpu-scheduling
Nazir Ahmed
 
UNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxUNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptx
ansariparveen06
 
ch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdfch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdf
SonaliAjankar
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
Shipra Swati
 
May14ProcessScheduling.ppt
May14ProcessScheduling.pptMay14ProcessScheduling.ppt
May14ProcessScheduling.ppt
ansariparveen06
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
Prakash Sir
 
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILEDCPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
VADAPALLYPRAVEENKUMA1
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
marangburu42
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formatting
marangburu42
 
Operating system
Operating systemOperating system
Operating system
devanshi_chowdhary
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
harini0810
 

Similar to Cpu scheduling (20)

Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
ch_scheduling (1).ppt
ch_scheduling (1).pptch_scheduling (1).ppt
ch_scheduling (1).ppt
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
CPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdfCPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdf
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Ch05 cpu-scheduling
Ch05 cpu-schedulingCh05 cpu-scheduling
Ch05 cpu-scheduling
 
UNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxUNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptx
 
ch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdfch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdf
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Section05 scheduling
Section05 schedulingSection05 scheduling
Section05 scheduling
 
May14ProcessScheduling.ppt
May14ProcessScheduling.pptMay14ProcessScheduling.ppt
May14ProcessScheduling.ppt
 
pscheduling.ppt
pscheduling.pptpscheduling.ppt
pscheduling.ppt
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILEDCPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
CPU SCHEDULING IN OPERATING SYSTEMS IN DETAILED
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formatting
 
Operating system
Operating systemOperating system
Operating system
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 

Recently uploaded

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
AkolbilaEmmanuel1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdfThe Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
Nettur Technical Training Foundation
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 

Recently uploaded (20)

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdfThe Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 

Cpu scheduling

  • 2. CPU Scheduling CPU scheduling is the basis of multiprogrammed operating systems. By switching the CPU among processes, the operating system can make the computer more productive. • In a single-processor system, only one process can run at a time. Others must wait until the CPU is free and can be rescheduled. • The objective of multiprogramming is to have some process running at all times, to maximize CPU utilization. • The idea is relatively simple. A process is executed until it must wait, typically for the completion of some I/O request. In a simple computer system, the CPU then just sits idle. All this waiting time is wasted; no useful work is accomplished. 2
  • 3. CPU Scheduling • With multiprogramming, we try to use this time productively. Several processes are kept in memory at one time. • When one process has to wait, the operating system takes the CPU away from that process and gives the CPU to another process. This pattern continues. Every time one process has to wait, another process can take over use of the CPU. 3
  • 4. CPU–I/O Burst Cycle • 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
  • 5. 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
  • 6. Dispatcher • Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: • switching context • switching to user mode • jumping to the proper location in the user program to restart that program • Dispatch latency – time it takes for the dispatcher to stop one process and start another running
  • 7. Scheduling Algorithms Basic categories: • Non-preemptive Mode: In this scheduling, a process continues to execute until it terminates. The process blocks itself to wait for I/O or by requesting some operating system service. • Preemptive Mode: The currently running process may be interrupted and moved to the Ready state by the operating system. The decision to preempt may be due to:  a new process arrives  an interrupt occurs that places a Blocked process in the Ready state  periodically on the basis of a clock interrupt. 7
  • 8. Scheduling Algorithms (1) Pure Priority Scheduling Scheme • Each process is assigned a priority. • The scheduler always chooses a process of higher priority over one of the lower priority. • Multiple “ready queues” with priorities RQ0 > RQ1 > … > RQn. • Process is selected from the highest priority ready queue. • Problem: Lower priority processes may suffer starvation, when there is a steady supply of higher-priority ready processes. • Solution: Priority of a process can change with its age or execution history. 8
  • 9. Priority Scheduling (Simplified Queuing Diagram) Processor . . . Release Time-out DispatchRQ0 Event-wait Block Queue Event Occur RQ1 RQn Scheduling Algorithms 9 Admit
  • 10. Example of Priority Scheduling ProcessAarri Burst TimeT Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 • Priority scheduling Gantt Chart • Average waiting time = 8.2 msec 1 0 1 19 P1 P2 16 P4 P3 6 18 PP2 P5
  • 11. SchedulingAlgorithms (2) First-Come, First-Served Scheme • First-Come, First-Served (FCFS) scheme is also called First-In, First-Out (FIFO) scheme. • The dispatcher runs the processes at head of single ready queue, new processes come in at the end of the queue. • Non-Preemptive technique • Shorter processes have to wait a lot while a long process is executed by processor. • FCFS tends to favor CPU-Bound processes over I/O-Bound processes. • FCFS is easier and faster but may result inefficient use of processor and the I/O devices. 11
  • 12. (2) First-Come, First-Served Scheme (con..) • I/O-Bound Processes: Processes that perform lots of I/O operations. Each I/O is followed by a short CPU burst. • CPU-Bound Processes: Processes that perform lots of computation and do little I/O. They tend to have long few CPU bursts. CPU burst: The amount of time the process uses the processor before it is no longer ready. Types of CPU bursts: • long bursts -- process is CPU bound (i.e. array work) • short bursts -- process I/O bound. 12 SchedulingAlgorithms
  • 13. First- Come, First-Served (FCFS) Scheduling: Example 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 • Convoy effect - short process behind long process • There is a convoy effect as all the other processes wait for the one big process to get off the CPU. This effect results in lower CPU and device utilization than might be possible if the shorter processes were allowed to go first. P P P1 2 3 0 24 3027
  • 14. FCFS Scheduling (Cont.) Suppose that the processes arrive in the order: P2 , P3 , P1 The Gantt chart for the schedule is: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Thus, the average waiting time under an FCFS policy is generally not minimal and may vary substantially if the processes’ CPU burst times vary greatly. P1 0 3 6 30 P2 P3
  • 15. SchedulingAlgorithms (3) Round-Robin Scheme The round-robin (RR) scheduling algorithm is designed especially for time- sharing systems. It is similar to FCFS scheduling, but preemption is added to enable the system to switch between processes. • A small unit of time, called a time quantum or time slice, is defined • If a process’s CPU burst exceeds 1 time quantum, that process is preempted and is put back in the ready queue. • A clock-interrupt is generated at periodic intervals. • When the interrupt occurs, the currently running process is placed in the Ready queue • Next process is selected on first-come, first-served basis. • Also known as time-slicing or time-quantization, because each process is given a slice / quantum of time 15
  • 16. SchedulingAlgorithms (3) Round-Robin Scheme (con…) Length or time quantum/slice: Short vs. Long • If the time quantum is very short, then short processes will move through the system relatively quickly. • However, there is processing overhead involved in handling the clock interrupt and performing the dispatching function. • Standard time quantum is slightly greater than the time required for a typical interaction. CPU-Bound vs. I/O-Bound Processes • I/O-bound processes tend to receive an unfair portion of processor time, which results in poor performance of I/O- bound processes. 16
  • 17. 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
  • 18. Time Quantum and Context Switch Time The performance of the RR algorithm depends heavily on the size of the time quantum. At one extreme, if the time quantum is extremely large, the RR policy. In contrast, if the time quantum is extremely small (say, 1 millisecond), the RR approach can result in a large number of context switches.
  • 19. SchedulingAlgorithms (4) Virtual Round-Robin Scheme • Similar to Round Robin • When a running process times out, it is returned to the Ready queue. • When a process is blocked for I/O, it joins an I/O queue. • Auxiliary Queue based on FCFS is used to which processes that are moved after being released from an I/O wait. • Processes in the auxiliary queue get preference over those in the main Ready queue. • Superior to the Round-Robin in terms of fairness. 19
  • 20. Queuing diagram for Virtual Round Robin Scheduler Processor Admit Release Time-out Dispatch Ready Queue Event 1 - wait Block Queue 1 Event 1 Occur Event 2 - wait Block Queue 2 Event 2 Occur Event n - wait Block Queue n Event n Occur Auxiliary Queue Scheduling Algorithms 20
  • 21. SchedulingAlgorithms (5) Shortest Job First Scheme • When the CPU is available, it is assigned to the process that has the smallest next CPU burst. • If the next CPU bursts of two processes are the same, FCFS scheduling is used to break the tie. • Note that a more appropriate term for this scheduling method would be the shortest-next- CPU-burst algorithm, because scheduling depends on the length of the next CPU burst of a process, rather than its total length. • Shortest Job First (SJF) is a non-preemptive policy • The difficulty with SJF policy is the “need to know the estimate time required for processing each process”. • Short processes will jump to the head of the queue past longer processes 21
  • 22. Example of SJF ProcessArriva l TimeBurst 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
  • 23. 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  
  • 24. SchedulingAlgorithms (6) Highest Response Ratio Next (HRRN) • The response ratio is given by RR = (w+s)/s where w = time spent waiting for the processor s = expected service time • Non-Preemptive scheme • When the current process completes or is blocked, choose the ready process with the largest value of RR. • This approach is attractive, because it accounts for the age of the process. • Shorter jobs are favored (a small denominator yields a larger ratio), aging without service increases the ratio. • As with the shortest process next, the expected time must be estimated before using the technique. 24
  • 25. Scheduling Algorithms (7) Feedback Scheme • This scheme is based on the time spent by a process in execution. • Scheduling is done on a preemptive basis, and a dynamic priority mechanism is used. • When a process first enters the system, it is placed in RQ0 (high priority queue). • When it returns to the Ready state after its first execution, it is placed in RQ1 (lower priority queue). • After each subsequent execution, it is demoted to the lower priority queue. • A shorter process will complete quickly, without migrating very far down the hierarchy of Ready queues. • A longer process will gradually drift downwards. 25
  • 26. Scheduling Algorithms (7) Feedback Scheme • Thus newer, shorter processes are favored over older longer processes. • Last queue is treated with Round Robin technique, while other are treated as FCFS 26 Processor Admit ReleaseDispatchRQ0 Processor RQ1 Processor RQn . . . Release * Dotted lines shows a time sequence rather than a static transitions.
  • 27. Scheduling Algorithms (8) Fair-Share Scheduling (FFS) Scheme • Preemptive technique • The processes are divided into groups • Each group is managed by certain scheme, mostly Round Robin Scheme is used • The turn take into account: • The CPU usage of the group to which the process belongs. • The technique used to schedule a process of a group (e.g. Round Robin, HRRN etc.) • Used when there is a multiuser system 27
  • 28. Consider the following set of processes that arrive at time 0, with the length of CPU-burst time given in milliseconds: Process Burst-Time P1 24 P2 3 P3 3 If we use a time quantum of 4 milliseconds, then find out the average waiting time with Round Robin (RR). Solution: Average waiting time (RR, q = 4) = (6+4+7)/3 = 5.66 0 to 3 4 to 6 7 to 9 10 to 29 Round Robin (q = 4) P1 P1 P2 P4 Scheduling Algorithms Examples 28
  • 29. Scheduling Algorithms Examples Consider the following set of processes, with the length of the CPU burst time given in milliseconds (excluding the transition time): Process Burst Time Priority P1 10 3 P2 1 1 P3 2 3 P4 1 4 P5 5 2 The processes are assumed to have arrived in the order P1, P2, P3, P3, P4, P5, all at time 0. (a) Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a non-preemptive priority (a smaller priority number implies a higher priority) and RR (quantum =1) scheduling. (b) What is the turnaround time of each process for each of the scheduling algorithm in part a? (c) What is the waiting time of each process for each of the scheduling algorithm in part a? (d) Which of the schedules in part a, results in the minimal average waiting time (over all processes)? 29
  • 30. (a) Gantt Chart 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 FCFS P1 P2 P3 P4 P5 SJF P2 P4 P3 P5 P1 Non-Preemptive Priority P2 P5 P3 P1 P4 Round Robin P1 P1 P1 P1 P1 P1 P2 P3 P3 P4 P5 P5 P5 P5 P5 Scheduling Algorithms Examples 30
  • 31. (b) Turnaround of each process & (c) Waiting time of each process (d) Minimal average waiting time According to above example, SJF technique results minimal average time of overall processes. Scheduling Algorithms Examples 31 P1 P2 P3 P4 P5 FCFS Turnaround 10 11 13 14 19 Waiting 0 10 11 13 14 SJF Turnaround 19 1 4 2 9 Waiting 9 0 2 1 4 Non-preemptive Priority Turnaround 18 1 9 19 6 Waiting 9 0 6 18 1 Round Robin Turnaround 19 2 7 4 14 Waiting 9 1 5 3 9
  • 32. Scheduling Algorithms Examples 32 Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. In answering the questions, use non- preemptive scheduling and base all decisions on the information you have at the time of the decision must be made. Process Arrival Time Burst Time P1 0.0 8 P2 0.4 4 P3 1.0 1 (a) What is the average turnaround time for these processes with the FCFS scheduling algorithm? (b) What is the average turnaround time of these processes for SJF scheduling algorithm? (c) The SJF algorithm is supposed to improve performance, but notice that we chose to run process P1 at time 0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be, if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm could be known as future-knowledge scheduling. Solution: Average turnaround time (Non-preemptive FCFS) = (8+12+13)/3 = 11 Average turnaround time (Non-preemptive SJF) = (8+9+13)/3 = 10 Average turnaround time (Non-preemptive+1 idle unit) = (1+6+14)/3 = 7