Introduction
Priority scheduling assigns each process a priority number and always runs the highest-priority ready process (by convention, a smaller number often means higher priority). Round Robin (RR) instead gives every ready process a fixed time slice, called a quantum, cycling through them in a circular queue. Priority scheduling optimizes for importance; Round Robin optimizes for fairness and responsiveness. Both are used heavily in real operating systems, often combined (e.g. Round Robin within each priority level).
Cricket analogy: A captain always throws the ball to the strike bowler with the best figures (priority scheduling) versus rotating every bowler for a fixed two-over spell in a T20 death-overs plan (Round Robin) to keep things fair and fresh.
Algorithm
/* Non-preemptive priority scheduling: pick the highest-priority (lowest
* number) process among those that have arrived and are not yet done. */
int pick_next_priority(process_t procs[], int prio[], int n, int done[], int clock) {
int best = -1;
for (int i = 0; i < n; i++) {
if (!done[i] && procs[i].arrival_time <= clock) {
if (best == -1 || prio[i] < prio[best]) best = i;
}
}
return best;
}
/* Aging: prevents starvation by boosting priority the longer a process waits. */
void apply_aging(int prio[], int wait_ticks[], int n) {
for (int i = 0; i < n; i++) {
if (wait_ticks[i] > 0 && wait_ticks[i] % 10 == 0) {
if (prio[i] > 0) prio[i]--; /* lower number = higher priority */
}
}
}
/* Round Robin: circular queue, each process runs for at most `quantum`. */
void round_robin(process_t procs[], int n, int quantum) {
int remaining[64];
for (int i = 0; i < n; i++) remaining[i] = procs[i].burst_time;
int queue[256], head = 0, tail = 0, clock = 0;
/* ... enqueue arrivals in order, then loop: dequeue, run min(quantum,
* remaining), enqueue any new arrivals, re-enqueue current process if
* remaining > 0, else record completion_time = clock ... */
}Explanation
Priority scheduling's central flaw is starvation: a low-priority process can wait forever if a steady stream of higher-priority processes keeps arriving. The standard fix is aging — gradually raising the priority of a process the longer it waits, guaranteeing it eventually becomes the highest priority and runs. Round Robin's central design decision is the time quantum. If the quantum is too small, the overhead of frequent context switches dominates (the CPU spends more time switching than doing useful work). If the quantum is too large, a process may finish or nearly finish its burst within one slice, and Round Robin degrades toward FCFS, losing its responsiveness advantage. A good rule of thumb is choosing a quantum where most CPU bursts complete within one or two time slices.
Cricket analogy: A part-time spinner never gets a bowl because the captain keeps favoring the strike pacers (starvation), so the coach mandates every bowler must get at least one over per hour of play (aging); Round Robin overs are timed at six balls -- too short and field resets eat the innings, too long and it becomes one bowler hogging the spell.
Example
/* -------- Priority scheduling (non-preemptive), all arrive at t=0 -------- *
* Process | Burst | Priority (1 = highest)
* P1 | 5 | 3
* P2 | 4 | 1
* P3 | 2 | 2
*
* Run order by priority: P2, P3, P1
* |----P2----|--P3--|-----P1-----|
* 0 4 6 11
*
* -------- Round Robin, quantum = 2 -------- *
* Process | Arrival | Burst
* P1 | 0 | 5
* P2 | 1 | 4
* P3 | 2 | 2
* P4 | 3 | 1
*
* |P1|P2|P3|P1|P4|P2|P1|
* 0 2 4 6 8 9 11 12
* (P3 completes at 6, P4 completes at 9, P2 completes at 11, P1 completes at 12)
*/
Output
Priority scheduling: completion times P2=4, P3=6, P1=11. Waiting times: P2=4-0-4=0, P3=6-0-2=4, P1=11-0-5=6, average waiting time = (0+4+6)/3 = 10/3 = 3.33. Turnaround times: P2=4, P3=6, P1=11, average turnaround = (4+6+11)/3 = 21/3 = 7.0. Round Robin (quantum 2): completion times are P3=6, P4=9, P2=11, P1=12. Turnaround = completion - arrival: P1=12-0=12, P2=11-1=10, P3=6-2=4, P4=9-3=6, giving average turnaround (12+10+4+6)/4 = 32/4 = 8.0. Waiting = turnaround - burst: P1=12-5=7, P2=10-4=6, P3=4-2=2, P4=6-1=5, giving average waiting time (7+6+2+5)/4 = 20/4 = 5.0.
Cricket analogy: Like ranking bowlers by economy rate to decide who bowls the death overs, priority scheduling here finishes P2 first (completion 4) giving it zero wait, while P1 waits through both rivals' spells before completing at 11, exactly as a low-priority bowler waits for the whole powerplay to pass.
Key Takeaways
- Priority scheduling always runs the highest-priority ready process; without aging, low-priority processes can starve indefinitely.
- Aging incrementally raises a waiting process's priority over time so it eventually gets scheduled, solving starvation.
- Round Robin gives every process a fixed quantum in circular order, guaranteeing bounded response time for all ready processes.
- Too small a quantum wastes CPU time on context-switch overhead; too large a quantum makes Round Robin behave like FCFS.
- Worked examples: priority scheduling gave average WT 3.33 / TAT 7.0; Round Robin (quantum 2) gave average WT 5.0 / TAT 8.0.
Practice what you learned
1. What technique prevents starvation in priority scheduling?
2. What happens if the Round Robin quantum is set very large (larger than any burst time)?
3. In the worked priority scheduling example, what is the average waiting time?
4. Why is a very small Round Robin quantum inefficient?
5. In the worked Round Robin example (quantum=2), which process completes first?
Was this page helpful?
You May Also Like
FCFS and SJF Scheduling
First-Come-First-Served and Shortest-Job-First scheduling, worked through Gantt charts with exact waiting/turnaround-time math.
Multilevel Queue Scheduling
How fixed-priority multilevel queues differ from adaptive multilevel feedback queues, and how each handles process movement.
Scheduling Algorithms Overview
How the CPU scheduler picks the next ready process, the metrics used to judge it, and the family of algorithms available.