Sub topic 15
Priority Scheduling, Starvation, and Aging
This chapter assumes you know process arrival time, burst time, ready queues, and the formulas for waiting time, turnaround time, and response time.
Priority Scheduling
Priority scheduling selects a ready process according to its priority. The priority rule must be stated because systems use different conventions:
- In some systems, a smaller number means higher priority.
- In others, a larger number means higher priority.
Unless a question says otherwise, state your convention before solving it. This chapter uses smaller numbers as higher priorities.
Priority scheduling can be:
- Non-preemptive: Once a process starts, it runs until completion.
- Preemptive: A newly arrived process can interrupt the running process if it has higher priority.
For equal priorities, use the stated tie-break rule. If none is given, FCFS order is a common assumption.
Worked Example: Non-Preemptive Scheduling
Consider these processes:
| Process | Arrival time | Burst time | Priority |
|---|---|---|---|
| P1 | 0 | 7 | 3 |
| P2 | 1 | 3 | 1 |
| P3 | 2 | 2 | 2 |
At time 0, only P1 is ready, so it starts. Non-preemptive scheduling does not interrupt P1 when P2 arrives.
The Gantt chart is:
0–7 P1 | 7–10 P2 | 10–12 P3
For each process:
- Turnaround time = completion time − arrival time
- Waiting time = turnaround time − burst time
- Response time = first-start time − arrival time
| Process | Completion | Turnaround | Waiting | Response |
|---|---|---|---|---|
| P1 | 7 | 7 | 0 | 0 |
| P2 | 10 | 9 | 6 | 6 |
| P3 | 12 | 10 | 8 | 8 |
The priority of P2 did not matter until the CPU became available at time 7.
Preemption and Starvation
In preemptive priority scheduling, a higher-priority arrival can interrupt a lower-priority process. This can improve response time for important work, but it can also cause starvation.
Starvation is indefinite postponement. A low-priority process remains ready but keeps losing the CPU to newly arriving high-priority processes.
Aging: The Standard Remedy
Aging gradually improves a waiting process's priority. For example, the operating system might increase a process's priority by one level after every five time units in the ready queue.
Aging preserves priority scheduling while limiting starvation. However, an overly aggressive aging rate can make the algorithm behave almost like FCFS. In a GATE problem, use the exact aging rule given and update priorities only at the stated times.
Exercise
Priorities use smaller numbers for higher priority. P1 is running at priority 4. A waiting process P2 has priority 6 and improves by one level every two time units. What is P2's priority after six time units?
Show answer
P2's priority improves three times: 6 → 5 → 4 → 3. Its priority is 3.