Professional Documents
Culture Documents
Chapter 5CPU Scheduling
Chapter 5CPU Scheduling
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
• Multiple-Processor Scheduling
• Real-Time Scheduling
• Algorithm Evaluation
P1 P2 P3
0 24 27 30
• Waiting time for P1 = 0; P2 = 24; P3 = 27
• Average waiting time: (0 + 24 + 27)/3 = 17
P2 P3 P1
0 3 6 30
• Associate with each process the length of its next CPU burst.
Use these lengths to schedule the process with the shortest time.
• Two schemes:
– nonpreemptive – once CPU given to the process it cannot
be preempted until completes its CPU burst.
– Preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time for a given
set of processes.
P2 8
P3 7
P4 3
• SJF (Non-Preemptive)
P4 P1 P3 P2
0 3 9 16 24
• Average waiting time = (3 + 16 + 9 + 0)/4 = 7milliseconds
• If UsingFCFS,the average wait time would be 10.25milli seconds
Operating System Concepts 5.12 Silberschatz and Galvin©1999
Example of Preemptive SJF
P1 P2 P4 P1 P3
0 5 10 17 26
1
τ n=1 = α tn + (1 − α )τ n .
• α =0
– τn+1 = τn
– Recent history does not count.
• α =1
– τn+1 = tn
– Only the actual last CPU burst counts.
• If we expand the formula, we get:
τn+1 = α tn+(1 - α) α tn -1 + …
+(1 - α )j α tn -1 + …
+(1 - α )n=1 tn τ0
• Since both α and (1 - α) are less than or equal to 1, each
successive term has less weight than its predecessor.
P2 P5 P1 P3 P
4
0 1 6 16 18 19
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
• Three queues:
– Q0 – time quantum 8 milliseconds
– Q1 – time quantum 16 milliseconds
– Q2 – FCFS
• Scheduling
– A new job enters queue Q0 which is served FCFS. When it
gains CPU, job receives 8 milliseconds. If it does not finish
in 8 milliseconds, job is moved to queue Q1.
– At Q1 job is again served FCFS and receives 16 additional
milliseconds. If it still does not complete, it is preempted
and moved to queue Q2.