Operating Systems - Ch6 - Mod - Reem
Operating Systems - Ch6 - Mod - Reem
Operating System Concepts, Avi Silberschatz, Peter Baer Galvin, Greg Gagne,
John Wiley & Sons, ISBN 978-1-118-06333-0 , 9th Ed., 2012.
CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Multiple-Processor Scheduling
Real-Time CPU Scheduling
Operating Systems Examples
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
One of the major drawbacks of this scheme is that the waiting time and
the average turnaround time is often quite long.
10 Operating System Dr. Reem Ibrahim
Scheduling Algorithms
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
SJF is optimal – gives minimum average waiting time for a given set of
processes
The difficulty is knowing the length of the next CPU request
Could ask the user
Can be done by using the length of previous CPU bursts, using exponential
averaging
1. t n actual length of n CPU burst
th
Commonly, α set to ½
n 1 t n 1 n .
=0
n+1 = n
Recent history does not
count
=1
n+1 = tn
Only the actual last CPU
burst counts
P1 P2 P4 P1 P3
0 1 5 10 17 26
The CPU is allocated to the process with the highest priority (smallest
integer highest priority)
Preemptive
Nonpreemptive
SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
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
Example: We have two processes, P1 and P2. The periods for P1 and P2
are 50 and 100, respectively—that is, p1 = 50 and p2 = 100. The processing
times are t1 = 20 for P1 and t2 = 35 for P2. The deadline for each process
requires that it complete its CPU burst by the start of its next period