SlideShare a Scribd company logo
Chapter 3
CPU scheduling
Scheduling
Module 3
• Objectives:
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
2
Scheduling
Module
3
• Topics To Be Covered:
• To introduce CPU scheduling, which is the basis for
multiprogram on operating systems
• To describe various CPU-scheduling algorithms ( There is no
one best solution. No one is perfect!)
• To discuss evaluation criteria for selecting a CPU-scheduling
algorithm for a particular system
3
Chapter 3
Processor Scheduling
Goal: Which and when a process takes processor time.
Levels
High ====== Admission: adds new comers to the system
Intermediate ====== Suspend/Resume: remove
temporary a process from competition on the processor or the
reverse.
Low ======Dispatch : pick a process from the
ready queue to have the processor
4
Chapter 3
Processor Scheduling
Objectives
Fair: The scheduler should Treat all processes in fair criteria's.
Throughput: Is the number of processes executed/ done per
unit time, the scheduler should try to maximize that number.
Support Active users : The active users have short jobs and that
requires fast service because they are setting in front of their
terminals waiting for system reply. So, scheduler should take in
consideration jobs that belong to active users to favor them.
5
Chapter 3
Processor Scheduling
Objectives
Predictable: A process executed many times in the system should be
finished within about the same duration i.e. the variance in execution time
should be small.
Overhead: schedulers take time to make the selection if that time is favor to
be as minimum as possible since that time is not paid by customers.
Maximize Resources utilization: computer resources utilization(operation)
means income and more services to customers which is desirable for the
scheduler. So, schedulers should try to maximize the operation of resources.
6
Chapter 3
Processor Scheduling
Objectives
No Indefinite Postponement: A process in the system should at some point
of time get the chance to have the processors. So, selection criteria of the
scheduler should take in consideration the process waiting time.
Support Priorities: Processes are normally not at the same level of
importance. So, the schedulers should give the ability to mark processes as
important over others.
Better Service For Best: A process that behaves logically and does not cause
much trouble to the OS should be favored over a process that does the
opposite.
7
Chapter 3
Processor Scheduling
Objectives
Degradation gracefully: It is logical if the system load increases
the system performance will degrade but it should degrade
with the same ratio of the load and not die at some point of
load.
8
Chapter 3
Basic Concepts
• Single Process  one process at a time.
• Maximum CPU utilization obtained with
multiprogramming.
• CPU idle :waiting time is wasted
9
Chapter 3
Basic Concepts
• Cycle – Process execution consists of a cycle of CPU
execution and I/O wait
• CPU burst: a time interval when a process uses CPU
only.
• I/O burst: a time interval when a process uses I/O
devices only.
Chapter 3 Alternating Sequence of CPU And I/O Bursts
11
Chapter 3
CPU Scheduler
• CPU idle , operating system selects one process
from ready Queue to be executed
• Many mechanisms: FIFO, priority …
• The Records in the queue are generally process
control block PCBs of the processes
12
Chapter 3
CPU Scheduler
• Long term scheduling
• Short term scheduling: CPU scheduler
• Medium term scheduling
13
Chapter 3
CPU Scheduler
• 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 in scheduling scheme is
nonpreemptive or cooperative;
• All other scheduling is preemptive
• Scheduler latency – time it takes for the Scheduler
to perform the select
14
Chapter 3
Dispatcher
• Scheduler (Algorithm + Data Structure) decides which
process to run next. Remember that decision always
take time and resources.
• Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler; this
involves:
• switching context
• switching to user mode
Note: Kernel runs in kernel mode/System 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
• At each clock interrupt, the OS gets to run and decide
whether the currently running process should be
allowed to continue or whether it has to choose
another process and give it the CPU.
15
Scheduling Criteria
Module 3
• CPU utilization – keep the CPU as busy as possible Maximize
• Throughput – # of processes that complete their execution per time unit Maximize
• Turnaround time – amount of time to execute a particular process (time from
submission to termination) Minimize
• Waiting time – amount of time a process has been waiting in ready queue Minimize
• Response time – amount of time it takes from when a request is submitted until the first
response is produced, not output (for time-sharing environment) Minimize
• Fairness- Give CPU to all processes in a fair manner
• SERVICE TIME The time required by a device to handle a request. (seconds) Minimize
• RESIDENCE TIME = SERVICE TIME + QUEUEING TIME. Minimize
16
Chapter 3 Processor Scheduling
Criteria’s
I/O bound: The operating system could learn from the behavior of the
process if the process perform many I/O’s compared to the use of the CPU. If
So, the OS mark that process as I/O bound.
CPU bound : The process that uses a lot of CPU time compared to rate of I/O
could be marked by the OS as CPU bound process.
Interactive/Batch : The operating system could have or know if the process is
to support interactive user waiting for response or it’s a batch process that is
no one is waiting for immediate response.
17
Chapter 3
Processor Scheduling
Criteria’s
Priority (static, dynamic, Purchased): OS could support priorities which could
be static, dynamic, or purchased. Static priority is given by the user or taken
from the user group and could not be changed during the life of the process
in the system. Dynamic priority is set initially be the submit process and
could be changed during the execution by the OS according to the behavior
of the process. Purchased is paid priorities that can not be altered by the OS
if dynamic
Page Faults: If Virtual storage is implemented the number of times the
process requests a page of the process that does not exist in real memory at
the time of request.
18
Chapter 3
Processor Scheduling
Criteria’s
Preemption (Preemptive (? Quantum Size( ): The preemption is the ability of
the OS to take the processor from a process by force. If the preemption is
allowed the OS has the control over the Quantum value. Quantum could be
fixed or vary from process to another.
Deadline: A process could have a deadline to complete.
A process that made to prevent some event from happening if finished after
that event then the result has know value.
Time to Complete: The OS can estimate the remaining of the execution time
if given the total time. So, it know how much time needed for the process to
finish and leave the system.
19
Chapter 3
Scheduling Algorithms
• First-Come, First-Served Scheduling
• Shortest-Job-First Scheduling
• Priority Scheduling
• Round-Robin Scheduling
• Multilevel Queue Scheduling
• Multilevel Feedback Queue Scheduling
20
Preemptive and Non Preemptive Scheduling
Module 3
• Nonpreemptive
• Once a process is allocated the CPU, it does not leave unless:
1. it has to wait, e.g., for I/O request or for a child to terminate
2. it terminates
• Preemptive
• OS can force (preempt) a process from CPU at anytime
• Say, to allocate CPU to another higher-priority process
21
Chapter 3
First-Come, First-Served (FCFS) Scheduling
• By far the simplest CPU-scheduling algorithm is the
first-come, first-served (FCFS) scheduling
algorithm.
• With this scheme, the process that requests the
CPU first is allocated the CPU first.
• The implementation of the FCFS policy is easily
managed with a FIFO queue
Chapter 3
First-Come, First-Served (FCFS) Scheduling
23
FIRST-COME, FIRST SERVED:
( FCFS) same as FIFO
Simple, fair, but poor performance. Average
queueing time may be long.
What are the average queueing and residence times
for this scenario?
How do average queueing and residence times
depend on ordering of these processes in the
queue?
Chapter 3
Processor Scheduling
Scheduling Disciplines (schemes)
Brust time/Service time : CPU time required
Turnaround Time(TAT)= finish time-time in
Wait Time(WT)= TAT-Brust time
24
First-Come, First-Served (FCFS) Scheduling
Module 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
• Turnaround time for P1 , P2 , and P3 are 24, 27, 30 respectively
• Average waiting time: (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 30
0
Burst Time
Process
24
P1
3
P2
3
P3
25
Chapter 3
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order
P2 , P3 , P1
• The Gantt chart for the schedule is:
• Turnaround time for P1 , P2 , and P3 are 30, 3, 6 respectively
• 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. Lower CPU and device
utilization than might be possible if the shorter processes were allowed to
get CPU first.
• FCFS is not suitable for time-sharing systems, where processes get a share of
CPU at regular intervals-> suitable for batch systems
P1
P3
P2
6
3 30
0
Chapter 3
FCFS Scheduling (Cont.)
• Example without ignoring arrival time.
Gantt Chart
0 8 12 21 26
• Average waiting time= [(0)+(8-1)+(12-2)+(21-3)]/4= 8.75 ms
• Average Turn Around time=[(8-0]+(12-1)+(21-2)+(26-3)]/4=15.25 ms
• Throughput = 4 jobs/26 ms = 0.15385 jobs/ms
P1 P2 P3 P4
Chapter 3
Shortest-Job-First (SJF) Scheduling
• Associate with each process the length of its next CPU burst. Use these lengths
to schedule the process with the shortest time. If several processes have the
same CPU next burst time, use FCFS to select one
Process Arrival Time Burst Time
P1 0.0 6
P2 0.0 8
P3 0.0 7
P4 0.0 3
 Non-Preemptive SJF scheduling Gannt chart (ignore arrival time)
 Turnaround time for P4 , P1 , P3 and P2 are 3, 9, 16, 24 respectively
 Average waiting time = (0 + 3+ 9 + 16) / 4 = 7 (ignore arrival time)
 Same problem with FCFS = 10.25 msec
P4 P3
P1
3 16
0 9
P2
24
Chapter 3
Process Arrival Time Burst Time
P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3
 Non-Preemptive SJF scheduling Gannt chart
P1 P3
P4
6 16
0 9
P2
24
 Turnaround time for P1 , P2 , P3 and P4 are 6, 24-2, 16-4, 9-5 respectively
 Average waiting time = (0 + (16-2)+ (9-4) + (6-5)) / 4 = 5
Chapter 3 Non-Preemptive Shortest-Job-First (SJF) Scheduling without
Ignoring Arrival time
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 Non-Preemptive SJF scheduling Gannt chart
 Turnaround time for P1 , P3 , P2 and P4 are
(7-0), (8-4), (12-2) , (16-5) respectively
7 , 4 , 10 , 11
 Average waiting time = (0 + (7-4) + (8-2) + (12-5) / 4 = 4
P1 P2
P3
7 12
0 8
P4
16
3
Scheduling
Module 3
• Which is harder to implement? and why?
•Preemptive is harder: Need to maintain consistency of data
shared between processes, and more importantly, kernel data
structures (e.g., I/O queues)
•Think of a preemption while kernel is executing a system call on
behalf of a process (many OSs, wait for system call to finish)
31
Chapter 3
Preemptive SJF Scheduler
• Preemptive SJF is optimal – gives minimum average waiting time for a given set
of processes because it moves short process before a long one. It can’t be used
for short-term scheduling
• It is used frequently in long-term scheduling in batch systems because user can
estimate running time needed
• Average waiting time= [(10-1)+(1-1)+(17-2)+(5-3)]/4= 6.5 ms
• Average Turn Around time=[(17-0]+(5-1)+(26-2)+(10-3)]/4=11.5 ms
• Throughput = 4 jobs/26 ms = 0.15385 jobs/ms
• Non-Preemptive scheduling waiting time = 7.75 ms
Chapter 3 Determining Length of Next CPU Burst
• The Real difficulty with the SJF algorithm is
knowing the length of the next CPU request
• We may not know but we can predict
• Optimal for minimizing queueing time, but
impossible to implement. Tries to predict the
process to schedule based on previous history.
Chapter 3 Shortest-Job-First (SJF) Scheduling without Ignoring Arrival
time
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
 Turnaround time for P1 , P2 , P3 and P4 are
(16-0), (7-2), (5-4) , (11-5) respectively
16 , 5 , 1 , 6
 Average waiting time = ((11-2) + (5-4)+ (4-4)+ (7-5)/ 4
 = ( 9 + 1 + 0 + 2 )/4 = 3
P1 P2
P3
4 7
0 5
P1
16
2
P2
11
P4
Chapter 3
Exercise 1
Assume you have the following jobs to execute with one processor, with
the jobs arriving in the order listed here
i T(pi)
0 80
1 20
2 10
3 20
4 50
Suppose a system uses FCFS and SJF scheduling .
1. Create a Gantt chart illustrating the execution of these processes?
2. What is the average wait time for the processes?
3. What is the turnaround time for process p3?
Chapter 3
Exercise 2
Assume you have the following jobs to execute with one processor, with
the jobs arriving in the order listed here
i arrival Time T(pi)
0 0 80
1 3 20
2 5 10
3 7 20
4 10 50
Suppose a system uses FCFS and SJF (preemptive and nonpreemptive)
scheduling.
1. Create a Gantt chart illustrating the execution of these processes?
2. What is the average wait time for the processes?
3. What is the turnaround time for process p3?
Priority Scheduling
Module 3
• Priority can be defined internally (to OS) or externally.
• Internal: CPU usage time, memory requirements, I/O usage
• External: importance, type, political issues
• A priority number (integer) is associated with each process
• The CPU is allocated to the process with the highest priority to be dispatched
• Preemptive
• Non-preemptive
• Non-preemptive once a process dispatched it runs to end
• In the preemptive priority scheme the dispatched process continues running until finish or
a comer with higher priority enters ready queue
• SJF is a priority scheduling where priority is the predicted next CPU burst time
• Problem  Starvation – low priority processes may never execute
• Solution  Aging – – As a process uses more execution time, dynamically decreases its priority or increase the
priority of other lower processes
37
Example of Priority Scheduling (nonpreemptive))
Module 3
• The Gantt chart is (all processes arrive at time 0):
• Average waiting time = (6 + 0 + 16 +18+1)/5 = 8.2
P2 P5
16
0 6
P1 P3
1 18
P4
19
Priority
Burst Time
Process
3
10
P1
1
1
P2
4
2
P3
5
1
P4
2
5
P5
38
Chapter 3
Assume 0 is the highest priority
Assume Cases:-
•Preemptive priority
•Non-preemptive priority
39
Process Burst Time
(ms)
Priority Arrival
Time
P1 10 3 0
P2 1 1 1
P3 2 3 2
P4 1 4 3
P5 5 2 4
Non-preemptive
As homework: compute average waiting time and average TAT
Waiting time P1=0
P2= 10-3=7
P5=11-4=7
P3= 16-2=14
P4=18-1=17
Chapter 3
Priority Scheduling-Example
Arrival time
0
3
2
1
4
Preemptive
P1 P2 P5 P1 P3 P4
0 1 2 3 4 9 16 18 19
P1= 9-3=6
P2=3-3=0
P3= 16-2=14
P4= 18-1=17
P5= 4-4=0
Chapter 3
Processor Scheduling
Scheduling Disciplines (schemes)
Round Robin (RR):
• It is the preemptive version of the FIFO.
• A process will wait in the queue until all the processes in
queue a head of it took at most quantum.
• A process will have the processor for a period of time equal
to at most quantum (usually 10-100 milliseconds).
• A process that took a full quantum on the processor will be
taken by the timer runout() and placed in the back of the
ready queue to wait for its turn to have the processor.
• We will consider favoring other commers to the queue over
the one leaving the processor
41
Example of RR with Time Quantum = 4
Module 3
• The Gantt chart is:
• Average waiting time = (0+4+7+(10-4))/3= 17/3= 5.66msec
• Typically, higher average turnaround than SJF, but better response
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Burst Time
Process
24
P1
3
P2
3
P3
42
Chapter 3
Typically, higher average turnaround than
SJF, but better responsiveness.
Average = [((6-2)+(10-8))+(2+(8-4))+(4+(9-
6))]/3=19/3= 6.33 msec. It gets better if the
quantum is chosen smaller
Sure all above numbers ignore context switch
time!
P1 P2 P3 P1 P2 P3 P1 P1
0 2 4 6 8 9 10 12 30
Quantum=2
Chapter 3
EXAMPLE DATA:
Process Arrival Service
Time Time
1 0 8
2 1 4
3 2 9
4 3 5
0 8 12 16 26
P2 P3 P4 P1
Round Robin, quantum = 4, no priority-based preemption
Average turn around = ( (20-0) + (8-1) + (26-2) + (25-3) )/4 = 74/4 = 18.5
P1
4
P3 P4
20 24 25
P3
CPU SCHEDULING
44
Scheduling
Algorithms
Note:
Example violates rules for
quantum size since most
processes don’t finish in one
quantum.
Average wait = ( (12) + (4-1) + ((8-2)+(20-12)+(25-24)) + ((12-3)+(24-16)) )/4 = 12+3+15+17= 47/4= 11.75
As homework compute draw time line graph
Chapter 3 Round-robin and Priority scheduling
Another option is to combine round-robin and priority scheduling in such
a way that the system executes the highest-priority process and runs processes
with the same priority using round-robin scheduling. Time Quantum= 2
Chapter 3 Time Quantum and Context Switch Time
Finish in
>1 Q
2 Q + Overhead
10 Q+9 * Overhead
Chapter 3
- Setting quantum too short  many process switches  lowers the
CPU efficiency. Suppose: quantum = 20 msec. process switch = 5
msec. This yields a 20% CPU waste time and 80% usage.
- Setting the quantum too long  may cause poor response time to
short interactive requests (e.g. 500 msec. And 5  CPU wasted
time less than 1%)
Time Quantum and Context Switch Time
Chapter 3 Turnaround Time Varies With The Time Quantum
Turnarround time
depends on size of
quantum .
Average turnaround
time does not
necessarily improves
as time quantum size
increase.
Chapter 3
Multilevel Queue Scheduling
• Suitable for the case where processes can be classified in different
groups according to some process criteria (type, size, priority,... )
• Multilevel Queue Scheduling partitions the Ready queue into several
separate queues according to response time requirement .
• Processes have different scheduling needs:
• foreground (interactive) -high response time and have external priority
• background (batch) – has less interaction and less priority
Chapter 3
Each queue has its own scheduling algorithm
foreground – RR
background – FCFS
Scheduling must be done between the queues. Two possibilities
1) Fixed priority scheduling; (i.e., serve all from foreground then
from background). Possibility of starvation.
If a student process is running and an interactive process
enters the ready queue, the student process will be
preempted.
Means that no process can run from batch if processes exist in
the higher priority queues-- Starvation is possible
Multilevel Queue Scheduling
Chapter 3
Multilevel Queue Scheduling(cont.)
2) 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 and 20% to background
in FCFS
Problem: normally a process enters a queue will remain there.
System does not move it from queue to queue!. Permanent
queue assignment
Chapter 3
Processor Scheduling
Scheduling Disciplines (schemes)
Shortest-Remaining-Time (SRT)
• The preemptive version of the SJF.
• The rule of this scheduler is at the time of the dispatch the shortest time
to finish job is selected to dispatch.
• Beside that whenever a job admitted to the ready queue if the time to
finish of that new comer is smaller than that of currently running it will
preemptive that job and new comer will be dispatched.
Process Burst Time
(ms)
Priority Arrival Time
P1 10 3 0
P2 1 1 1
P3 2 3 2
P4 1 4 3
P5 5 2 4
52
Chapter 3
Processor Scheduling
Scheduling Disciplines (schemes)
Highest Response Ratio (HRR)
For each job a head of each dispatch even the following ratio is
computed
RR= (Waiting Time + Service Time) /Service Time
The job of the highest RR will be selected for dispatch
53
Chapter 3
Processor Scheduling
Scheduling Disciplines (schemes)
Multilevel Feedback Queues (MLQ)
• The scheduler has set the following goal to satisfy:-
• Favor short jobs
• Favor I/O Bound
• Determine Job Nature Quick
• Quantum gets larger as level # get higher
• The implementation is done through the use of multiples
queues with different priorities in network.
• The process will enter the network at the highest queue.
• The process that consume a full quantum of a queue will be
set-down to the next queue down the network.
54
Chapter 3
Processor Scheduling
Scheduling Disciplines (schemes)
Multilevel Feedback Queues (MLQ)
• The process that reaches the lowest queue will round robin in that
queue until it finish execution.
• Each queue has quantum the get bigger from the highest to the lowest
queue.
• When ever the job leaves the network for I/O it will be set to start from
the highest level (the network forget the history). The highest queue is
the one of the highest priority So, a process will never run unless all the
queue above its queue is empty.
• A variation from the original I/O back criteria is to let the process back
one queue higher than the one it was in before the I/O.
55
Chapter 3
Multilevel Feedback Queue Scheduling
• A process can move between the various queues:
• Separate processes according to their CPU bursts characteristics
• If a process uses too much CPU, move it to lower priority queue
• Use aging to prevent starvation
• If a process stay too long to get CPU, move it to higher priority
queue
• 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
Chapter 3 Example of Multilevel Feedback Queue
• Three queues with different Q and priority and scheduling algorithm:
• Q0 – RR with time quantum 8 milliseconds (Highest priority)
• Q1 – RR time quantum 16 milliseconds
• Q2 – FCFS (Lowest priority)
• Scheduling
• A new job enters queue Q0 which is served FCFS basis . 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 basis and receives 16 additional
milliseconds. If it still does not complete, it is preempted and
moved to queue Q2.
Chapter 3
Multilevel Feedback Queue
Short Process has higher priority:
-Always run processes in Q0
-Only when Q0 is empty, processes in Q1 or Q2 (if Q1 is
empty)get CPU
-Preempt running process from Q1 or Q2 when a process
enters Q0
Chapter 3
2
4
SJF
Multilevel Feedback Queue
Chapter 3
P1 P2
3 4 7 8 12
P1
P1
P1
3 5 7 11 13 14 18 22 24 25 26
P2
5 7 9 13 22 23
P2
P3
P1
P4
P3
P3
P4
11 18 21 26
P2 P3 P2
P2 P3
TIME= 13 22 23
P1 2 13
P2 1 12 13
P3 3 8 9
P4 1 1
P1
P2
P3
P1
Chapter 3
Multilevel Feedback Queue
P1=7-5+22-11=13
P2=5-4+14-7+24-18=14
P3=11-8+18-13+25-22=11
P4=13-12=1
Chapter 3
P2 has been upgraded at time 24
from Q3 to Q2
Queue Network
Q1
Q2
Q3
Qn
Leave network
Finish or for I/O
New Commers to the
network
Q1<Q2<Q3 …<Qn
63
Chapter 3
Assume 4 queues network
Q1=0.5
Q2=1
Q3=1.5
Q4=2
Average TAT
Average WT
64
Process Burst Time (ms) Arrival Time
P1 10 0
P2 2 1
P3 7 3
P4 1 5
P5 8 7
Chapter 3
Test yourself
• Priority
• SJF
• FCFS
Chapter 3
Answer : priority
Chapter 3
Answer : SJF
Chapter 3
Answer : FCFS
Chapter 3
End lecture
3
Thank You
Ad

More Related Content

Similar to Lecture 3 CPU scheduling.pdfvgukgiolphpiphjp (20)

Lecture 4 - Process Scheduling.pptx
Lecture 4 - Process Scheduling.pptxLecture 4 - Process Scheduling.pptx
Lecture 4 - Process Scheduling.pptx
Amanuelmergia
 
Lecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptxLecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptx
Amanuelmergia
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
KeyreSebre
 
CPU Scheduling_in_processManagement.pptx
CPU Scheduling_in_processManagement.pptxCPU Scheduling_in_processManagement.pptx
CPU Scheduling_in_processManagement.pptx
ezekielnyamu1
 
May14ProcessScheduling.ppt
May14ProcessScheduling.pptMay14ProcessScheduling.ppt
May14ProcessScheduling.ppt
ansariparveen06
 
pscheduling.ppt
pscheduling.pptpscheduling.ppt
pscheduling.ppt
ansariparveen06
 
In computing, scheduling is the action .
In computing, scheduling is the action .In computing, scheduling is the action .
In computing, scheduling is the action .
nathansel1
 
CPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdfCPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdf
Harika Pudugosula
 
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 ALGORITHMS-FCFS,SJF,RR.pptx
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptxCPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
Rajapriya82
 
Scheduling.ppt with operating system slides
Scheduling.ppt with operating system slidesScheduling.ppt with operating system slides
Scheduling.ppt with operating system slides
lovepreet33653
 
3Chapter Three- CPU Scheduling this is the best.pptx
3Chapter Three- CPU Scheduling this is the best.pptx3Chapter Three- CPU Scheduling this is the best.pptx
3Chapter Three- CPU Scheduling this is the best.pptx
habtegebeyawu
 
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
manideepakc
 
programming .pptx
programming .pptxprogramming .pptx
programming .pptx
SHUJEHASSAN
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
amadayshwan
 
CPU scheduling in Operating System Explanation
CPU scheduling in Operating System ExplanationCPU scheduling in Operating System Explanation
CPU scheduling in Operating System Explanation
AnitaSofiaKeyser
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
Prakash Sir
 
Operating System.pptx
Operating System.pptxOperating System.pptx
Operating System.pptx
VanshikaRajput33
 
UNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxUNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptx
ansariparveen06
 
Chapter No 4 CPU Scheduling and Algorithms.ppt
Chapter No 4 CPU Scheduling and Algorithms.pptChapter No 4 CPU Scheduling and Algorithms.ppt
Chapter No 4 CPU Scheduling and Algorithms.ppt
rajaghogre22
 
Lecture 4 - Process Scheduling.pptx
Lecture 4 - Process Scheduling.pptxLecture 4 - Process Scheduling.pptx
Lecture 4 - Process Scheduling.pptx
Amanuelmergia
 
Lecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptxLecture 4 - Process Scheduling (1).pptx
Lecture 4 - Process Scheduling (1).pptx
Amanuelmergia
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
KeyreSebre
 
CPU Scheduling_in_processManagement.pptx
CPU Scheduling_in_processManagement.pptxCPU Scheduling_in_processManagement.pptx
CPU Scheduling_in_processManagement.pptx
ezekielnyamu1
 
May14ProcessScheduling.ppt
May14ProcessScheduling.pptMay14ProcessScheduling.ppt
May14ProcessScheduling.ppt
ansariparveen06
 
In computing, scheduling is the action .
In computing, scheduling is the action .In computing, scheduling is the action .
In computing, scheduling is the action .
nathansel1
 
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 ALGORITHMS-FCFS,SJF,RR.pptx
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptxCPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
CPU SCHEDULING ALGORITHMS-FCFS,SJF,RR.pptx
Rajapriya82
 
Scheduling.ppt with operating system slides
Scheduling.ppt with operating system slidesScheduling.ppt with operating system slides
Scheduling.ppt with operating system slides
lovepreet33653
 
3Chapter Three- CPU Scheduling this is the best.pptx
3Chapter Three- CPU Scheduling this is the best.pptx3Chapter Three- CPU Scheduling this is the best.pptx
3Chapter Three- CPU Scheduling this is the best.pptx
habtegebeyawu
 
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
manideepakc
 
programming .pptx
programming .pptxprogramming .pptx
programming .pptx
SHUJEHASSAN
 
CPU scheduling in Operating System Explanation
CPU scheduling in Operating System ExplanationCPU scheduling in Operating System Explanation
CPU scheduling in Operating System Explanation
AnitaSofiaKeyser
 
UNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptxUNIPROCESS SCHEDULING.pptx
UNIPROCESS SCHEDULING.pptx
ansariparveen06
 
Chapter No 4 CPU Scheduling and Algorithms.ppt
Chapter No 4 CPU Scheduling and Algorithms.pptChapter No 4 CPU Scheduling and Algorithms.ppt
Chapter No 4 CPU Scheduling and Algorithms.ppt
rajaghogre22
 

Recently uploaded (20)

Sets theories and applications that can used to imporve knowledge
Sets theories and applications that can used to imporve knowledgeSets theories and applications that can used to imporve knowledge
Sets theories and applications that can used to imporve knowledge
saumyasl2020
 
hersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distributionhersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distribution
hershtara1
 
Process Mining as Enabler for Digital Transformations
Process Mining as Enabler for Digital TransformationsProcess Mining as Enabler for Digital Transformations
Process Mining as Enabler for Digital Transformations
Process mining Evangelist
 
L1_Slides_Foundational Concepts_508.pptx
L1_Slides_Foundational Concepts_508.pptxL1_Slides_Foundational Concepts_508.pptx
L1_Slides_Foundational Concepts_508.pptx
38NoopurPatel
 
AWS-Certified-ML-Engineer-Associate-Slides.pdf
AWS-Certified-ML-Engineer-Associate-Slides.pdfAWS-Certified-ML-Engineer-Associate-Slides.pdf
AWS-Certified-ML-Engineer-Associate-Slides.pdf
philsparkshome
 
national income & related aggregates (1)(1).pptx
national income & related aggregates (1)(1).pptxnational income & related aggregates (1)(1).pptx
national income & related aggregates (1)(1).pptx
j2492618
 
HershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistributionHershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistribution
hershtara1
 
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
bastakwyry
 
Red Hat Openshift Training - openshift (1).pptx
Red Hat Openshift Training - openshift (1).pptxRed Hat Openshift Training - openshift (1).pptx
Red Hat Openshift Training - openshift (1).pptx
ssuserf60686
 
report (maam dona subject).pptxhsgwiswhs
report (maam dona subject).pptxhsgwiswhsreport (maam dona subject).pptxhsgwiswhs
report (maam dona subject).pptxhsgwiswhs
AngelPinedaTaguinod
 
Mining a Global Trade Process with Data Science - Microsoft
Mining a Global Trade Process with Data Science - MicrosoftMining a Global Trade Process with Data Science - Microsoft
Mining a Global Trade Process with Data Science - Microsoft
Process mining Evangelist
 
presentacion.slideshare.informáticaJuridica..pptx
presentacion.slideshare.informáticaJuridica..pptxpresentacion.slideshare.informáticaJuridica..pptx
presentacion.slideshare.informáticaJuridica..pptx
GersonVillatoro4
 
Process Mining at Deutsche Bank - Journey
Process Mining at Deutsche Bank - JourneyProcess Mining at Deutsche Bank - Journey
Process Mining at Deutsche Bank - Journey
Process mining Evangelist
 
How Netflix Uses Big Data to Personalize Audience Viewing Experience
How Netflix Uses Big Data to Personalize Audience Viewing ExperienceHow Netflix Uses Big Data to Personalize Audience Viewing Experience
How Netflix Uses Big Data to Personalize Audience Viewing Experience
PromptCloudTechnolog
 
AWS Certified Machine Learning Slides.pdf
AWS Certified Machine Learning Slides.pdfAWS Certified Machine Learning Slides.pdf
AWS Certified Machine Learning Slides.pdf
philsparkshome
 
Controlling Financial Processes at a Municipality
Controlling Financial Processes at a MunicipalityControlling Financial Processes at a Municipality
Controlling Financial Processes at a Municipality
Process mining Evangelist
 
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
muhammed84essa
 
CS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docxCS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docx
nidarizvitit
 
Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...
Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...
Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...
Jayantilal Bhanushali
 
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
disnakertransjabarda
 
Sets theories and applications that can used to imporve knowledge
Sets theories and applications that can used to imporve knowledgeSets theories and applications that can used to imporve knowledge
Sets theories and applications that can used to imporve knowledge
saumyasl2020
 
hersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distributionhersh's midterm project.pdf music retail and distribution
hersh's midterm project.pdf music retail and distribution
hershtara1
 
Process Mining as Enabler for Digital Transformations
Process Mining as Enabler for Digital TransformationsProcess Mining as Enabler for Digital Transformations
Process Mining as Enabler for Digital Transformations
Process mining Evangelist
 
L1_Slides_Foundational Concepts_508.pptx
L1_Slides_Foundational Concepts_508.pptxL1_Slides_Foundational Concepts_508.pptx
L1_Slides_Foundational Concepts_508.pptx
38NoopurPatel
 
AWS-Certified-ML-Engineer-Associate-Slides.pdf
AWS-Certified-ML-Engineer-Associate-Slides.pdfAWS-Certified-ML-Engineer-Associate-Slides.pdf
AWS-Certified-ML-Engineer-Associate-Slides.pdf
philsparkshome
 
national income & related aggregates (1)(1).pptx
national income & related aggregates (1)(1).pptxnational income & related aggregates (1)(1).pptx
national income & related aggregates (1)(1).pptx
j2492618
 
HershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistributionHershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistribution
hershtara1
 
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
2-Raction quotient_١٠٠١٤٦.ppt of physical chemisstry
bastakwyry
 
Red Hat Openshift Training - openshift (1).pptx
Red Hat Openshift Training - openshift (1).pptxRed Hat Openshift Training - openshift (1).pptx
Red Hat Openshift Training - openshift (1).pptx
ssuserf60686
 
report (maam dona subject).pptxhsgwiswhs
report (maam dona subject).pptxhsgwiswhsreport (maam dona subject).pptxhsgwiswhs
report (maam dona subject).pptxhsgwiswhs
AngelPinedaTaguinod
 
Mining a Global Trade Process with Data Science - Microsoft
Mining a Global Trade Process with Data Science - MicrosoftMining a Global Trade Process with Data Science - Microsoft
Mining a Global Trade Process with Data Science - Microsoft
Process mining Evangelist
 
presentacion.slideshare.informáticaJuridica..pptx
presentacion.slideshare.informáticaJuridica..pptxpresentacion.slideshare.informáticaJuridica..pptx
presentacion.slideshare.informáticaJuridica..pptx
GersonVillatoro4
 
How Netflix Uses Big Data to Personalize Audience Viewing Experience
How Netflix Uses Big Data to Personalize Audience Viewing ExperienceHow Netflix Uses Big Data to Personalize Audience Viewing Experience
How Netflix Uses Big Data to Personalize Audience Viewing Experience
PromptCloudTechnolog
 
AWS Certified Machine Learning Slides.pdf
AWS Certified Machine Learning Slides.pdfAWS Certified Machine Learning Slides.pdf
AWS Certified Machine Learning Slides.pdf
philsparkshome
 
Controlling Financial Processes at a Municipality
Controlling Financial Processes at a MunicipalityControlling Financial Processes at a Municipality
Controlling Financial Processes at a Municipality
Process mining Evangelist
 
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
muhammed84essa
 
CS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docxCS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docx
nidarizvitit
 
Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...
Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...
Day 1 MS Excel Basics #.pptxDay 1 MS Excel Basics #.pptxDay 1 MS Excel Basics...
Jayantilal Bhanushali
 
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
indonesia-gen-z-report-2024 Gen Z (born between 1997 and 2012) is currently t...
disnakertransjabarda
 
Ad

Lecture 3 CPU scheduling.pdfvgukgiolphpiphjp

  • 2. Scheduling Module 3 • Objectives: • Basic Concepts • Scheduling Criteria • Scheduling Algorithms 2
  • 3. Scheduling Module 3 • Topics To Be Covered: • To introduce CPU scheduling, which is the basis for multiprogram on operating systems • To describe various CPU-scheduling algorithms ( There is no one best solution. No one is perfect!) • To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system 3
  • 4. Chapter 3 Processor Scheduling Goal: Which and when a process takes processor time. Levels High ====== Admission: adds new comers to the system Intermediate ====== Suspend/Resume: remove temporary a process from competition on the processor or the reverse. Low ======Dispatch : pick a process from the ready queue to have the processor 4
  • 5. Chapter 3 Processor Scheduling Objectives Fair: The scheduler should Treat all processes in fair criteria's. Throughput: Is the number of processes executed/ done per unit time, the scheduler should try to maximize that number. Support Active users : The active users have short jobs and that requires fast service because they are setting in front of their terminals waiting for system reply. So, scheduler should take in consideration jobs that belong to active users to favor them. 5
  • 6. Chapter 3 Processor Scheduling Objectives Predictable: A process executed many times in the system should be finished within about the same duration i.e. the variance in execution time should be small. Overhead: schedulers take time to make the selection if that time is favor to be as minimum as possible since that time is not paid by customers. Maximize Resources utilization: computer resources utilization(operation) means income and more services to customers which is desirable for the scheduler. So, schedulers should try to maximize the operation of resources. 6
  • 7. Chapter 3 Processor Scheduling Objectives No Indefinite Postponement: A process in the system should at some point of time get the chance to have the processors. So, selection criteria of the scheduler should take in consideration the process waiting time. Support Priorities: Processes are normally not at the same level of importance. So, the schedulers should give the ability to mark processes as important over others. Better Service For Best: A process that behaves logically and does not cause much trouble to the OS should be favored over a process that does the opposite. 7
  • 8. Chapter 3 Processor Scheduling Objectives Degradation gracefully: It is logical if the system load increases the system performance will degrade but it should degrade with the same ratio of the load and not die at some point of load. 8
  • 9. Chapter 3 Basic Concepts • Single Process  one process at a time. • Maximum CPU utilization obtained with multiprogramming. • CPU idle :waiting time is wasted 9
  • 10. Chapter 3 Basic Concepts • Cycle – Process execution consists of a cycle of CPU execution and I/O wait • CPU burst: a time interval when a process uses CPU only. • I/O burst: a time interval when a process uses I/O devices only.
  • 11. Chapter 3 Alternating Sequence of CPU And I/O Bursts 11
  • 12. Chapter 3 CPU Scheduler • CPU idle , operating system selects one process from ready Queue to be executed • Many mechanisms: FIFO, priority … • The Records in the queue are generally process control block PCBs of the processes 12
  • 13. Chapter 3 CPU Scheduler • Long term scheduling • Short term scheduling: CPU scheduler • Medium term scheduling 13
  • 14. Chapter 3 CPU Scheduler • 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 in scheduling scheme is nonpreemptive or cooperative; • All other scheduling is preemptive • Scheduler latency – time it takes for the Scheduler to perform the select 14
  • 15. Chapter 3 Dispatcher • Scheduler (Algorithm + Data Structure) decides which process to run next. Remember that decision always take time and resources. • Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: • switching context • switching to user mode Note: Kernel runs in kernel mode/System 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 • At each clock interrupt, the OS gets to run and decide whether the currently running process should be allowed to continue or whether it has to choose another process and give it the CPU. 15
  • 16. Scheduling Criteria Module 3 • CPU utilization – keep the CPU as busy as possible Maximize • Throughput – # of processes that complete their execution per time unit Maximize • Turnaround time – amount of time to execute a particular process (time from submission to termination) Minimize • Waiting time – amount of time a process has been waiting in ready queue Minimize • Response time – amount of time it takes from when a request is submitted until the first response is produced, not output (for time-sharing environment) Minimize • Fairness- Give CPU to all processes in a fair manner • SERVICE TIME The time required by a device to handle a request. (seconds) Minimize • RESIDENCE TIME = SERVICE TIME + QUEUEING TIME. Minimize 16
  • 17. Chapter 3 Processor Scheduling Criteria’s I/O bound: The operating system could learn from the behavior of the process if the process perform many I/O’s compared to the use of the CPU. If So, the OS mark that process as I/O bound. CPU bound : The process that uses a lot of CPU time compared to rate of I/O could be marked by the OS as CPU bound process. Interactive/Batch : The operating system could have or know if the process is to support interactive user waiting for response or it’s a batch process that is no one is waiting for immediate response. 17
  • 18. Chapter 3 Processor Scheduling Criteria’s Priority (static, dynamic, Purchased): OS could support priorities which could be static, dynamic, or purchased. Static priority is given by the user or taken from the user group and could not be changed during the life of the process in the system. Dynamic priority is set initially be the submit process and could be changed during the execution by the OS according to the behavior of the process. Purchased is paid priorities that can not be altered by the OS if dynamic Page Faults: If Virtual storage is implemented the number of times the process requests a page of the process that does not exist in real memory at the time of request. 18
  • 19. Chapter 3 Processor Scheduling Criteria’s Preemption (Preemptive (? Quantum Size( ): The preemption is the ability of the OS to take the processor from a process by force. If the preemption is allowed the OS has the control over the Quantum value. Quantum could be fixed or vary from process to another. Deadline: A process could have a deadline to complete. A process that made to prevent some event from happening if finished after that event then the result has know value. Time to Complete: The OS can estimate the remaining of the execution time if given the total time. So, it know how much time needed for the process to finish and leave the system. 19
  • 20. Chapter 3 Scheduling Algorithms • First-Come, First-Served Scheduling • Shortest-Job-First Scheduling • Priority Scheduling • Round-Robin Scheduling • Multilevel Queue Scheduling • Multilevel Feedback Queue Scheduling 20
  • 21. Preemptive and Non Preemptive Scheduling Module 3 • Nonpreemptive • Once a process is allocated the CPU, it does not leave unless: 1. it has to wait, e.g., for I/O request or for a child to terminate 2. it terminates • Preemptive • OS can force (preempt) a process from CPU at anytime • Say, to allocate CPU to another higher-priority process 21
  • 22. Chapter 3 First-Come, First-Served (FCFS) Scheduling • By far the simplest CPU-scheduling algorithm is the first-come, first-served (FCFS) scheduling algorithm. • With this scheme, the process that requests the CPU first is allocated the CPU first. • The implementation of the FCFS policy is easily managed with a FIFO queue
  • 23. Chapter 3 First-Come, First-Served (FCFS) Scheduling 23 FIRST-COME, FIRST SERVED: ( FCFS) same as FIFO Simple, fair, but poor performance. Average queueing time may be long. What are the average queueing and residence times for this scenario? How do average queueing and residence times depend on ordering of these processes in the queue?
  • 24. Chapter 3 Processor Scheduling Scheduling Disciplines (schemes) Brust time/Service time : CPU time required Turnaround Time(TAT)= finish time-time in Wait Time(WT)= TAT-Brust time 24
  • 25. First-Come, First-Served (FCFS) Scheduling Module 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 • Turnaround time for P1 , P2 , and P3 are 24, 27, 30 respectively • Average waiting time: (0 + 24 + 27)/3 = 17 P1 P2 P3 24 27 30 0 Burst Time Process 24 P1 3 P2 3 P3 25
  • 26. Chapter 3 FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P2 , P3 , P1 • The Gantt chart for the schedule is: • Turnaround time for P1 , P2 , and P3 are 30, 3, 6 respectively • 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. Lower CPU and device utilization than might be possible if the shorter processes were allowed to get CPU first. • FCFS is not suitable for time-sharing systems, where processes get a share of CPU at regular intervals-> suitable for batch systems P1 P3 P2 6 3 30 0
  • 27. Chapter 3 FCFS Scheduling (Cont.) • Example without ignoring arrival time. Gantt Chart 0 8 12 21 26 • Average waiting time= [(0)+(8-1)+(12-2)+(21-3)]/4= 8.75 ms • Average Turn Around time=[(8-0]+(12-1)+(21-2)+(26-3)]/4=15.25 ms • Throughput = 4 jobs/26 ms = 0.15385 jobs/ms P1 P2 P3 P4
  • 28. Chapter 3 Shortest-Job-First (SJF) Scheduling • Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. If several processes have the same CPU next burst time, use FCFS to select one Process Arrival Time Burst Time P1 0.0 6 P2 0.0 8 P3 0.0 7 P4 0.0 3  Non-Preemptive SJF scheduling Gannt chart (ignore arrival time)  Turnaround time for P4 , P1 , P3 and P2 are 3, 9, 16, 24 respectively  Average waiting time = (0 + 3+ 9 + 16) / 4 = 7 (ignore arrival time)  Same problem with FCFS = 10.25 msec P4 P3 P1 3 16 0 9 P2 24
  • 29. Chapter 3 Process Arrival Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3  Non-Preemptive SJF scheduling Gannt chart P1 P3 P4 6 16 0 9 P2 24  Turnaround time for P1 , P2 , P3 and P4 are 6, 24-2, 16-4, 9-5 respectively  Average waiting time = (0 + (16-2)+ (9-4) + (6-5)) / 4 = 5
  • 30. Chapter 3 Non-Preemptive Shortest-Job-First (SJF) Scheduling without Ignoring Arrival time Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  Non-Preemptive SJF scheduling Gannt chart  Turnaround time for P1 , P3 , P2 and P4 are (7-0), (8-4), (12-2) , (16-5) respectively 7 , 4 , 10 , 11  Average waiting time = (0 + (7-4) + (8-2) + (12-5) / 4 = 4 P1 P2 P3 7 12 0 8 P4 16 3
  • 31. Scheduling Module 3 • Which is harder to implement? and why? •Preemptive is harder: Need to maintain consistency of data shared between processes, and more importantly, kernel data structures (e.g., I/O queues) •Think of a preemption while kernel is executing a system call on behalf of a process (many OSs, wait for system call to finish) 31
  • 32. Chapter 3 Preemptive SJF Scheduler • Preemptive SJF is optimal – gives minimum average waiting time for a given set of processes because it moves short process before a long one. It can’t be used for short-term scheduling • It is used frequently in long-term scheduling in batch systems because user can estimate running time needed • Average waiting time= [(10-1)+(1-1)+(17-2)+(5-3)]/4= 6.5 ms • Average Turn Around time=[(17-0]+(5-1)+(26-2)+(10-3)]/4=11.5 ms • Throughput = 4 jobs/26 ms = 0.15385 jobs/ms • Non-Preemptive scheduling waiting time = 7.75 ms
  • 33. Chapter 3 Determining Length of Next CPU Burst • The Real difficulty with the SJF algorithm is knowing the length of the next CPU request • We may not know but we can predict • Optimal for minimizing queueing time, but impossible to implement. Tries to predict the process to schedule based on previous history.
  • 34. Chapter 3 Shortest-Job-First (SJF) Scheduling without Ignoring Arrival time Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4  Turnaround time for P1 , P2 , P3 and P4 are (16-0), (7-2), (5-4) , (11-5) respectively 16 , 5 , 1 , 6  Average waiting time = ((11-2) + (5-4)+ (4-4)+ (7-5)/ 4  = ( 9 + 1 + 0 + 2 )/4 = 3 P1 P2 P3 4 7 0 5 P1 16 2 P2 11 P4
  • 35. Chapter 3 Exercise 1 Assume you have the following jobs to execute with one processor, with the jobs arriving in the order listed here i T(pi) 0 80 1 20 2 10 3 20 4 50 Suppose a system uses FCFS and SJF scheduling . 1. Create a Gantt chart illustrating the execution of these processes? 2. What is the average wait time for the processes? 3. What is the turnaround time for process p3?
  • 36. Chapter 3 Exercise 2 Assume you have the following jobs to execute with one processor, with the jobs arriving in the order listed here i arrival Time T(pi) 0 0 80 1 3 20 2 5 10 3 7 20 4 10 50 Suppose a system uses FCFS and SJF (preemptive and nonpreemptive) scheduling. 1. Create a Gantt chart illustrating the execution of these processes? 2. What is the average wait time for the processes? 3. What is the turnaround time for process p3?
  • 37. Priority Scheduling Module 3 • Priority can be defined internally (to OS) or externally. • Internal: CPU usage time, memory requirements, I/O usage • External: importance, type, political issues • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority to be dispatched • Preemptive • Non-preemptive • Non-preemptive once a process dispatched it runs to end • In the preemptive priority scheme the dispatched process continues running until finish or a comer with higher priority enters ready queue • SJF is a priority scheduling where priority is the predicted next CPU burst time • Problem  Starvation – low priority processes may never execute • Solution  Aging – – As a process uses more execution time, dynamically decreases its priority or increase the priority of other lower processes 37
  • 38. Example of Priority Scheduling (nonpreemptive)) Module 3 • The Gantt chart is (all processes arrive at time 0): • Average waiting time = (6 + 0 + 16 +18+1)/5 = 8.2 P2 P5 16 0 6 P1 P3 1 18 P4 19 Priority Burst Time Process 3 10 P1 1 1 P2 4 2 P3 5 1 P4 2 5 P5 38
  • 39. Chapter 3 Assume 0 is the highest priority Assume Cases:- •Preemptive priority •Non-preemptive priority 39 Process Burst Time (ms) Priority Arrival Time P1 10 3 0 P2 1 1 1 P3 2 3 2 P4 1 4 3 P5 5 2 4 Non-preemptive As homework: compute average waiting time and average TAT Waiting time P1=0 P2= 10-3=7 P5=11-4=7 P3= 16-2=14 P4=18-1=17
  • 40. Chapter 3 Priority Scheduling-Example Arrival time 0 3 2 1 4 Preemptive P1 P2 P5 P1 P3 P4 0 1 2 3 4 9 16 18 19 P1= 9-3=6 P2=3-3=0 P3= 16-2=14 P4= 18-1=17 P5= 4-4=0
  • 41. Chapter 3 Processor Scheduling Scheduling Disciplines (schemes) Round Robin (RR): • It is the preemptive version of the FIFO. • A process will wait in the queue until all the processes in queue a head of it took at most quantum. • A process will have the processor for a period of time equal to at most quantum (usually 10-100 milliseconds). • A process that took a full quantum on the processor will be taken by the timer runout() and placed in the back of the ready queue to wait for its turn to have the processor. • We will consider favoring other commers to the queue over the one leaving the processor 41
  • 42. Example of RR with Time Quantum = 4 Module 3 • The Gantt chart is: • Average waiting time = (0+4+7+(10-4))/3= 17/3= 5.66msec • Typically, higher average turnaround than SJF, but better response P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30 Burst Time Process 24 P1 3 P2 3 P3 42
  • 43. Chapter 3 Typically, higher average turnaround than SJF, but better responsiveness. Average = [((6-2)+(10-8))+(2+(8-4))+(4+(9- 6))]/3=19/3= 6.33 msec. It gets better if the quantum is chosen smaller Sure all above numbers ignore context switch time! P1 P2 P3 P1 P2 P3 P1 P1 0 2 4 6 8 9 10 12 30 Quantum=2
  • 44. Chapter 3 EXAMPLE DATA: Process Arrival Service Time Time 1 0 8 2 1 4 3 2 9 4 3 5 0 8 12 16 26 P2 P3 P4 P1 Round Robin, quantum = 4, no priority-based preemption Average turn around = ( (20-0) + (8-1) + (26-2) + (25-3) )/4 = 74/4 = 18.5 P1 4 P3 P4 20 24 25 P3 CPU SCHEDULING 44 Scheduling Algorithms Note: Example violates rules for quantum size since most processes don’t finish in one quantum. Average wait = ( (12) + (4-1) + ((8-2)+(20-12)+(25-24)) + ((12-3)+(24-16)) )/4 = 12+3+15+17= 47/4= 11.75 As homework compute draw time line graph
  • 45. Chapter 3 Round-robin and Priority scheduling Another option is to combine round-robin and priority scheduling in such a way that the system executes the highest-priority process and runs processes with the same priority using round-robin scheduling. Time Quantum= 2
  • 46. Chapter 3 Time Quantum and Context Switch Time Finish in >1 Q 2 Q + Overhead 10 Q+9 * Overhead
  • 47. Chapter 3 - Setting quantum too short  many process switches  lowers the CPU efficiency. Suppose: quantum = 20 msec. process switch = 5 msec. This yields a 20% CPU waste time and 80% usage. - Setting the quantum too long  may cause poor response time to short interactive requests (e.g. 500 msec. And 5  CPU wasted time less than 1%) Time Quantum and Context Switch Time
  • 48. Chapter 3 Turnaround Time Varies With The Time Quantum Turnarround time depends on size of quantum . Average turnaround time does not necessarily improves as time quantum size increase.
  • 49. Chapter 3 Multilevel Queue Scheduling • Suitable for the case where processes can be classified in different groups according to some process criteria (type, size, priority,... ) • Multilevel Queue Scheduling partitions the Ready queue into several separate queues according to response time requirement . • Processes have different scheduling needs: • foreground (interactive) -high response time and have external priority • background (batch) – has less interaction and less priority
  • 50. Chapter 3 Each queue has its own scheduling algorithm foreground – RR background – FCFS Scheduling must be done between the queues. Two possibilities 1) Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. If a student process is running and an interactive process enters the ready queue, the student process will be preempted. Means that no process can run from batch if processes exist in the higher priority queues-- Starvation is possible Multilevel Queue Scheduling
  • 51. Chapter 3 Multilevel Queue Scheduling(cont.) 2) 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 and 20% to background in FCFS Problem: normally a process enters a queue will remain there. System does not move it from queue to queue!. Permanent queue assignment
  • 52. Chapter 3 Processor Scheduling Scheduling Disciplines (schemes) Shortest-Remaining-Time (SRT) • The preemptive version of the SJF. • The rule of this scheduler is at the time of the dispatch the shortest time to finish job is selected to dispatch. • Beside that whenever a job admitted to the ready queue if the time to finish of that new comer is smaller than that of currently running it will preemptive that job and new comer will be dispatched. Process Burst Time (ms) Priority Arrival Time P1 10 3 0 P2 1 1 1 P3 2 3 2 P4 1 4 3 P5 5 2 4 52
  • 53. Chapter 3 Processor Scheduling Scheduling Disciplines (schemes) Highest Response Ratio (HRR) For each job a head of each dispatch even the following ratio is computed RR= (Waiting Time + Service Time) /Service Time The job of the highest RR will be selected for dispatch 53
  • 54. Chapter 3 Processor Scheduling Scheduling Disciplines (schemes) Multilevel Feedback Queues (MLQ) • The scheduler has set the following goal to satisfy:- • Favor short jobs • Favor I/O Bound • Determine Job Nature Quick • Quantum gets larger as level # get higher • The implementation is done through the use of multiples queues with different priorities in network. • The process will enter the network at the highest queue. • The process that consume a full quantum of a queue will be set-down to the next queue down the network. 54
  • 55. Chapter 3 Processor Scheduling Scheduling Disciplines (schemes) Multilevel Feedback Queues (MLQ) • The process that reaches the lowest queue will round robin in that queue until it finish execution. • Each queue has quantum the get bigger from the highest to the lowest queue. • When ever the job leaves the network for I/O it will be set to start from the highest level (the network forget the history). The highest queue is the one of the highest priority So, a process will never run unless all the queue above its queue is empty. • A variation from the original I/O back criteria is to let the process back one queue higher than the one it was in before the I/O. 55
  • 56. Chapter 3 Multilevel Feedback Queue Scheduling • A process can move between the various queues: • Separate processes according to their CPU bursts characteristics • If a process uses too much CPU, move it to lower priority queue • Use aging to prevent starvation • If a process stay too long to get CPU, move it to higher priority queue • 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
  • 57. Chapter 3 Example of Multilevel Feedback Queue • Three queues with different Q and priority and scheduling algorithm: • Q0 – RR with time quantum 8 milliseconds (Highest priority) • Q1 – RR time quantum 16 milliseconds • Q2 – FCFS (Lowest priority) • Scheduling • A new job enters queue Q0 which is served FCFS basis . 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 basis and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.
  • 58. Chapter 3 Multilevel Feedback Queue Short Process has higher priority: -Always run processes in Q0 -Only when Q0 is empty, processes in Q1 or Q2 (if Q1 is empty)get CPU -Preempt running process from Q1 or Q2 when a process enters Q0
  • 60. Chapter 3 P1 P2 3 4 7 8 12 P1 P1 P1 3 5 7 11 13 14 18 22 24 25 26 P2 5 7 9 13 22 23 P2 P3 P1 P4 P3 P3 P4 11 18 21 26 P2 P3 P2 P2 P3 TIME= 13 22 23 P1 2 13 P2 1 12 13 P3 3 8 9 P4 1 1 P1 P2 P3 P1
  • 61. Chapter 3 Multilevel Feedback Queue P1=7-5+22-11=13 P2=5-4+14-7+24-18=14 P3=11-8+18-13+25-22=11 P4=13-12=1
  • 62. Chapter 3 P2 has been upgraded at time 24 from Q3 to Q2
  • 63. Queue Network Q1 Q2 Q3 Qn Leave network Finish or for I/O New Commers to the network Q1<Q2<Q3 …<Qn 63
  • 64. Chapter 3 Assume 4 queues network Q1=0.5 Q2=1 Q3=1.5 Q4=2 Average TAT Average WT 64 Process Burst Time (ms) Arrival Time P1 10 0 P2 2 1 P3 7 3 P4 1 5 P5 8 7
  • 65. Chapter 3 Test yourself • Priority • SJF • FCFS
  • 66. Chapter 3 Answer : priority
  翻译: