Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Thread Scheduling
Multiple-Processor Scheduling
Real-Time CPU Scheduling
Operating Systems Examples
Algorithm Evaluation
P1 P2 P3
0 24 27 30
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
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
P4 P1 P3 P2
0 3 9 16 24
Can only estimate the length – should be similar to the previous one
Then pick process with shortest predicted next CPU burst
Commonly, α set to ½
Preemptive version called shortest-remaining-time-first
=0
n+1 = n
Recent history does not count
=1
n+1 = tn
Only the actual last CPU burst counts
If we expand the formula, we get:
n+1 = tn+(1 - ) tn -1 + …
+(1 - )j tn -j + …
+(1 - )n +1 0
P1 P2 P4 P1 P3
0 1 5 10 17 26
Each process gets a small unit of CPU time (time quantum q),
usually 10-100 milliseconds. After this time has elapsed, the
process is preempted and added to the end of the ready queue.
If there are n processes in the ready queue and the time
quantum is q, then each process gets 1/n of the CPU time in
chunks of at most q time units at once. No process waits more
than (n-1)q time units.
Timer interrupts every quantum to schedule next process
Performance
q large FIFO
q small q must be large with respect to context switch,
otherwise overhead is too high
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
4 3 3 3 2
t5 t4 t3 t2 t1