How do priority and multilevel queue scheduling work, and how does aging prevent starvation?
Answer
Priority scheduling gives every process a priority number and always runs the highest-priority ready process; often a smaller number means a higher priority. It can be preemptive or non-preemptive. Multilevel queue scheduling splits the ready queue into separate queues by process type, for example a foreground queue for interactive processes and a background queue for batch jobs, each with its own algorithm and a fixed priority between the queues.
- Both can cause starvation: a low-priority process may wait forever if higher-priority work keeps arriving.
- Aging fixes this by gradually raising the priority of a process the longer it waits, so it eventually runs.
- A multilevel feedback queue also lets processes move between queues: CPU-heavy processes are demoted and long-waiting ones are promoted.
Example: non-preemptive priority, all arriving at time 0 (lower number = higher priority):
| Process | Burst | Priority | Runs | Waiting |
|---|---|---|---|---|
| P2 | 2 | 1 | 0–2 | 0 |
| P3 | 3 | 2 | 2–5 | 2 |
| P1 | 4 | 3 | 5–9 | 5 |
Average waiting = 7 / 3 ≈ 2.33. If new priority-1 jobs kept arriving, P1 could starve; with aging, its priority improves every few seconds until it reaches the top. Similarly, a background FCFS queue runs only when the foreground Round Robin queue is empty.