Priority Scheduling
Important work first — and the starvation problem that creates.
Skip to the animationPriority scheduling gives every process a number and always dispatches the most important one waiting. Everything else about it — including SJF — is a special case of choosing what that number means.
How it works
Each process carries a priority. When the CPU frees up, the ready process with the best priority runs; ties are broken FCFS. In this course, and in most textbooks, a lower number means a higher priority — priority 1 beats priority 5. (Some real systems invert that, so always check the convention before answering.)
It comes in both flavours. Non-preemptive — the version animated below — lets the running process finish even if something more important arrives. Preemptive takes the CPU away the moment a higher-priority process becomes ready.
SJF *is* priority scheduling, with priority = predicted next burst. Recognising that saves memorising two algorithms.
Where priorities come from
- Internal (computed by the OS)
- Measurable quantities: memory footprint, ratio of CPU to I/O usage, time limits, how long it has already waited. The system sets these itself.
- External (set from outside)
- Policy, not measurement: which user paid, which department owns the job, whether it is a system daemon or a background backup.
niceon Unix is the everyday example.
Starvation and ageing
This is the defining problem of priority scheduling: a low-priority process may never run, because higher-priority work keeps arriving. It is not blocked or deadlocked — it is simply always second best. The lore is that when MIT shut down its IBM 7094 in 1973, they found a low-priority job submitted in 1967 that had still never run.
The standard fix is ageing: gradually improve the priority of any process that has been waiting. Raise a job's priority by one step for every 15 minutes it has waited, and even a priority-127 job eventually outranks new arrivals — turning “never” into “eventually”, which is the guarantee a scheduler actually needs.
A related hazard is priority inversion: a high-priority process waits on a lock held by a low-priority one, which is itself never scheduled. The fix is priority inheritance — while it holds the lock, the low-priority process temporarily inherits the waiter's priority.
The vocabulary
- Arrival time
- When the process shows up in the ready queue. The scheduler cannot pick something that has not arrived yet — that single rule decides most exam answers.
- Burst time
- How long this process needs the CPU for, uninterrupted, before it would block or finish. Also called CPU burst.
- Ready queue
- Every process that could run right now but does not have the CPU. Scheduling is entirely the question of who gets pulled out of here next.
- Preemptive vs non-preemptive
- A non-preemptive scheduler cannot take the CPU back — once dispatched, a process runs until it blocks or finishes. A preemptive one can interrupt it mid-burst.
- Context switch
- Saving one process's registers and loading another's. Pure overhead: real work stops while it happens, typically a few microseconds.
- Starvation
- A process that stays runnable but never gets picked, because something more attractive keeps arriving. The classic fix is ageing — slowly raising the priority of anything that has waited a long time.
Multilevel queues
Real systems rarely use one flat priority list. They split the ready queue into several queues — interactive, batch, system — each with its own priority and often its own internal algorithm (Round Robin for the interactive queue, FCFS for the batch one). Multilevel feedback queues go further and move a process between queues based on observed behaviour: use your whole quantum and you drop a level (you look CPU-bound); block early and you rise (you look interactive). That is ageing and burst prediction combined, and it is roughly what Linux, Windows and macOS actually do.
The numbers you will be asked for
- Turnaround time
completion − arrival
Total time the process spent in the system, from the moment it arrived to the moment it finished.
- Waiting time
turnaround − burst
The part of that which was pure waiting. It is the only part a scheduler can actually change — the burst is fixed work.
- Response time
first run − arrival
How long until the process gets the CPU for the first time. This is what an interactive user actually feels.
- Throughput
processes ÷ total time
How much work the machine completes per unit of time.
Advantages and disadvantages
Advantages
- Important work goes first — the only algorithm here that can express that at all.
- Flexible: choose the priority function and you get FCFS, SJF or a deadline scheduler.
- Supports both preemptive and non-preemptive use, and layers naturally into multilevel queues.
Disadvantages
- Indefinite blocking (starvation) of low-priority processes, unless ageing is added.
- Priority inversion can stall the very work you marked as most important.
- Assigning meaningful priorities is a policy problem with no correct answer.
- Average waiting time can be much worse than SJF if priorities ignore burst length.
Watch it work
Check yourself
question 1 / 4
One question at a time. Pick an answer to see why it is right or wrong, then move on — there is no score to keep and nothing is saved.