










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











































Source: Operating System Concepts by by Silberschatz, Galvin and Gagne
CPU scheduling is fundamental to multiprogramming OS Deals with problem of deciding which of processes in the ready queue is to be allocated the CPU.
What we cover: Basic concepts Scheduling criteria Scheduling algorithms Multiple-processor scheduling Thread scheduling Real-time scheduling Algorithm evaluation OS examples
Durations of CPU bursts have a typical frequency curve (exponential or hyper-exponential): many short bursts – an I/O bound program a few long bursts – a CPU bound program.
CPU scheduler (also called short-term scheduler) selects from among the processes in ready queue, and allocates the CPU to one of them.
CPU scheduling decision may take place when a process:
Scheduling under 1 and 4 is nonpreemptive.
Once the CPU is allocated to a process, the process keeps the CPU until it switches to waiting state or terminates.
All other scheduling is preemptive.
Incurs a cost.
Criteria for comparing CPU-scheduling algorithms:
CPU utilization – keep the CPU as busy as possible (0 to 100% efficiency).
Throughput – # of processes that complete their execution per time unit
Turnaround time – amount of time to execute a particular process waiting for memory + ready queue + execution + I/O
Waiting time – amount of time a process waits in the ready queue
Response time – amount of time it takes from when a request was submitted until the first response is produced.
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
Optimize the max or min values or average measure or variance.
Process Burst Time (ms) P 1 24 P 2 3 P 3 3
Suppose that the processes arrive in the order: P 1 , P 2 , P 3 The Gantt Chart for the schedule is:
Average waiting time: (0 + 24 + 27)/3 = 17 milliseconds
Average turnaround time =?
P 1 P 2 P 3
0 24 27 30
Suppose that the processes arrive in the order
P 2 , P 3 , P 1
The Gantt chart for the schedule is:
Average waiting time: (6 + 0 + 3)/3 = 3 ms
Much better than previous case.
Convoy effect - short process behind long process
P 2 P 3 P 1
0 3 6 30
CSC 4103: Operating System 5.13 BB Karki, LSU
Challenge is to know the length of the next CPU request:
Approximate prediction of the length of next CPU burst: from the lengths of previous CPU bursts by using exponential averaging running average of each burst for each process.
1
α α
τ (^) n
th
€
τ (^) n + 1 = α tn + (^) ( 1 − α) τ (^) n
α =
τn+1 = τn Recent history does not count.
α =
τn+1 = tn Only the actual last CPU burst counts.
If we expand the formula, we get:
τn+1 = α tn + (1 - α) α tn-1 + …
Since both α and (1 - α) are less than or equal to 1, each successive term has less weight than its predecessor.
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 known as the Shortest-Remaining-Time-First ( SRTF ).
Preemptive improves average waiting time.
Process Arrival Time Burst Time P 1 0 7 P 2 2 4 P 3 4 1 P 4 5 4
SJF (non-preemptive)
Average waiting time = (0 + 6 + 3 + 7)/4 = 4 ms.
P 1 P 3 P 2
0 3 7 16
P 4
8 12
A priority is associated with each process, and the CPU is allocated to the process with the highest priority. smallest integer ≡ highest priority.
SJF is a priority scheduling where priority is the inverse of the predicted next CPU burst time.
Process Burst Time Priority P 1 10 3 P 2 1 1 P 3 2 4 P 4 1 5 P 5 5 2
Average waiting time is 8.2 ms
P 2 P 5 P 1 P 3
0 1 6 16 18 19
P 4
Priorities can be defined internally or externally
Priority scheduling can be preemptive or non-preemptive
Problem ≡ Starvation
Low priority processes may never be executed. e.g., a low-priority process submitted in 1967 never ran until the shutdown of IBM 7094 at MIT in 1973.
Solution ≡ Aging
As time progresses, increase the priority of the process.