3.4 Priority Scheduling & Starvation (Aging Technique)
💡 Core Intuition
🍳 The Everyday Analogy: Airport Boarding & VIP Express Lanes
Imagine an airport boarding gate where a single gate agent (the CPU) validates boarding passes for hundreds of passengers waiting to board an aircraft:
The Airport Boarding Priority Pipeline
Mapping boarding class hierarchies to OS Priority CPU scheduling
Passenger Queue
Passengers arrive at the gate holding different ticket classes.
Boarding Walkway
Once a passenger steps onto the jet bridge, they board without interruption.
VIP Jump & Aging
VIP passengers jump the line; delayed passengers receive priority upgrades.
- Priority Assignment: Critical passengers (crew members, medical responders, VIPs) take precedence over general travelers.
- The Starvation Dilemma: If high-priority VIP passengers arrive continuously, economy passengers at the back of the line might miss the flight entirely. The solution is Aging—gradually boosting an economy passenger's priority the longer they stand waiting.
💻 Bridging to Computer Science
In operating systems, Priority Scheduling associates a priority rank with each process.
- At any scheduling instant, the Short-Term Scheduler allocates the CPU to the available process with the highest priority.
- If two processes share identical priority values, FCFS order is used to break the tie.
- Systems implement Priority Scheduling in both Non-Preemptive and Preemptive modes.
In academic literature and operating system designs, two opposite numbering conventions exist:
- Lower Number = Higher Priority: Standard UNIX/Linux nice values, where is high priority and is low priority.
- Higher Number = Higher Priority: Common in real-time kernels and standard university problem sets, where a higher integer (e.g., ) denotes superior priority over a smaller integer (e.g., ). Always verify the declared convention before solving. In this chapter, we adopt the standard convention: Higher Integer Value = Higher Priority.
📚 Core Deep-Dive & Concepts
1. Priority Scheduling Architectural Principles
Definition: A priority is associated with each process. At any instance of time out of all available processes, the CPU is allocated to the process that possesses the highest priority. Tie is broken using FCFS order. It supports both non-preemptive and preemptive versions.
Non-Preemptive vs. Preemptive Priority Scheduling
Contrasting cooperative completion against dynamic preemption
Non-Preemptive Priority
- •Scheduling Trigger: Evaluated only when running task completes or blocks for I/O.
- •Zero Preemption: A running process is never evicted, even if a higher-priority task arrives.
- •Low Context Switching: Eliminates cache invalidation and register thrashing.
- •Bounded Responsiveness: Urgent system alerts must wait until current burst finishes.
Preemptive Priority
- •Scheduling Trigger: Evaluated immediately whenever a new process enters the Ready Queue.
- •Dynamic Context Switch: Evicts the running process if newcomer has higher priority.
- •Optimal Responsiveness: Mission-critical tasks execute with near-zero latency.
- •Severe Starvation Risk: Low-priority jobs can be frozen indefinitely under heavy loads.
2. Comprehensive Problem: Non-Preemptive Priority Scheduling
Consider six processes with their arrival times, burst times, and priorities (where Higher Number denotes Higher Priority, with being Highest):
| Process ID | Arrival Time () | Burst Time () | Priority |
|---|---|---|---|
Step-by-Step Execution Sequence:
- : CPU is idle for .
- At : Only is present (). Since scheduling is non-preemptive, runs uninterrupted to completion ().
- At : completes (). All other processes () are now in the Ready Queue:
- The scheduler chooses the highest priority: (Priority 8). executes for ().
- At : completes (). Highest available priority is (Priority 7). executes for ().
- At : completes (). Highest available priority is (Priority 6). executes for ().
- At : completes (). Remaining processes are (Priority 5) and (Priority 5).
- Tie-Breaking via FCFS: arrived at ; arrived at . Therefore, is scheduled first.
- executes for ().
- At : completes (). Only remains. executes for ().
- At : All processes complete execution.
Non-Preemptive Priority Execution Gantt Chart
Timeline showing non-preemptive execution ordered strictly by priority (8 -> 7 -> 6 -> 5 -> 5)
Tabulation of Non-Preemptive Priority Metrics:
| Process | Priority | Completion () | Turnaround () | Waiting () | Response () | ||
|---|---|---|---|---|---|---|---|
3. Preemptive Priority Scheduling Step-by-Step Derivation
Definition: In Preemptive Priority scheduling, the process with the highest priority is allocated the CPU. If a new process enters the system with a priority strictly higher than the priority of the currently running process, a context switch occurs and the CPU is immediately reassigned to the higher-priority newcomer.
Applying preemption to the exact same six processes:
Chronological Preemption Execution Walkthrough:
- : CPU idle.
- At : arrives (Priority 4). Begins executing.
- At : (Priority 5) and (Priority 7) arrive.
- Running process has Priority 4.
- Both newcomers have higher priority, and the highest is (Priority 7).
- preempts ! has run for (remaining: ).
- begins executing ().
- At : (Priority 8) and (Priority 5) arrive.
- Running process has Priority 7.
- Newcomer has Priority 8, which is strictly higher than 7!
- preempts ! has run for (remaining: ).
- begins executing ().
- (At , arrives with Priority 6. Since , continues uninterrupted to completion).
- At : completes ().
- Ready Queue candidates: (Priority 7, rem ), (Priority 6, rem ), (Priority 5, rem ), (Priority 5, rem ), (Priority 4, rem ).
- Highest priority is (Priority 7). resumes and finishes its remaining (, ).
- At : completes. Highest available priority is (Priority 6). executes for (, ).
- At : completes. Candidates are (Priority 5) and (Priority 5).
- Tie broken by FCFS arrival: runs before .
- executes for (, ).
- At : completes. executes for (, ).
- At : Only remains (Priority 4). resumes and finishes its remaining (, ).
- At : All processes complete.
Preemptive Priority Execution Gantt Chart
Tracing dynamic preemption points at t = 2 (P2 preempts P0) and t = 3 (P3 preempts P2)
Tabulation of Preemptive Priority Metrics:
| Process | Priority | Completion () | Turnaround () | Waiting () | Response () | ||
|---|---|---|---|---|---|---|---|
4. Advantages, Disadvantages & Starvation
Advantages of Priority Scheduling:
- Preferential Facility for System Processes: Provides dedicated priority execution to critical kernel daemons, device interrupt services, and audio/graphics drivers.
- Allows Important Service Execution: Ensures urgent batch or security workloads preempt standard user applications whenever necessary.
Disadvantages of Priority Scheduling:
- Indefinite Blocking (Starvation): Processes with lower priorities may sit in the Ready Queue forever if higher-priority processes arrive continuously.
- Unpredictable Latency: No mathematical guarantee on turnaround time or waiting time for lower-tier processes.
5. Starvation Mitigation: The Aging Technique
Definition: Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time.
The Starvation Elimination Aging Pipeline
How periodic timer-driven priority boosts guarantee progress for low-priority processes
Low Priority Process
Process enters Ready Queue with lowest initial priority.
First Priority Boost
Kernel timer handler detects threshold wait and increments priority.
Highest Priority Run
Eventually matches highest priority and is guaranteed CPU dispatch.
Aging Mechanics:
- For example, the kernel can increase a waiting process's priority by every (or every few hundred timer interrupts).
- A process that entered with a minimal priority of will, after of waiting, reach priority , competing on equal terms with the highest-priority tasks in the system.
- Result: Starvation is mathematically eliminated.
📐 Architecture / Visual Blueprint
Priority Inversion Architecture & Priority Inheritance Solution
A critical concurrency flaw in real-time priority systems is Priority Inversion, where a low-priority task holds a lock needed by a high-priority task, while medium-priority tasks prevent the low-priority task from finishing:
The Priority Inversion Problem & Priority Inheritance Fix
Tracing how an un-inverted priority schedule protects high-priority real-time deadlines
T_L Acquires Mutex Lock
T_H Blocks on Mutex
Priority Inversion Occurs!
Priority Inheritance Protocol Applied
🏭 In The Real World: Production Case Study
The Mars Pathfinder Priority Inversion Glitch (1997)
One of the most famous real-world systems software bugs occurred during NASA's Mars Pathfinder mission:
Mars Pathfinder VxWorks Real-Time Thread Hierarchy
The three concurrent threads that triggered the historic 1997 Martian system reset
Information Bus Thread (bc_dist)
Critical spacecraft attitude control thread starved while awaiting the shared bus mutex.
Communications Thread (ASI/MET)
Long-running radio transmitter tasks that preempted low-priority tasks freely.
Meteorological Sensor Task
Background science measurement thread that held the contended shared memory mutex.
Incident Breakdown:
- A low-priority meteorological sensor task acquired an information bus mutex.
- A high-priority attitude control thread requested the mutex and was blocked.
- Multiple medium-priority communications tasks arrived and ran uninterrupted, preventing the low-priority task from finishing and releasing the lock.
- An automated watchdog timer detected that the high-priority attitude task was stalled, assumed total system failure, and triggered a full spacecraft computer reset.
- The Fix: Engineers uploaded a patch enabling the Priority Inheritance Protocol on the mutex, ensuring any task holding a contended lock temporarily inherits the priority of the highest blocked thread.
🎯 Exam & Interview Pitfall Check
Question 1: Define Priority Scheduling. Explain the fundamental difference in dispatcher behavior between its non-preemptive and preemptive forms. Answer:
- Definition: A scheduling scheme where each process is assigned a priority integer, and the Short-Term Scheduler dispatches the available process with the highest priority. FCFS resolves ties.
- Dispatcher Differences:
- In Non-Preemptive Priority, when a high-priority process arrives, the dispatcher takes no action; the currently running process retains the CPU until it voluntarily yields or finishes.
- In Preemptive Priority, the arrival of a higher-priority process triggers an immediate interrupt, saving the running process's registers to its PCB and context-switching to the newcomer.
Question 2: What is Starvation, and how does the Aging technique resolve it? Answer:
- Starvation: The permanent or indefinite denial of CPU resources to low-priority processes caused by a steady stream of higher-priority arrivals.
- Aging: The gradual increment of an awaiting process's priority over time (e.g., priority every ). Eventually, every starving process reaches the highest priority tier and executes.
- The Number Direction Trap: Always verify whether represents the highest or lowest priority before calculating . Assuming is highest when a problem defines higher integers as higher priority inverts the entire Gantt chart.
- Assuming Preemption Happens on Equal Priority: If process with priority 5 is executing and process arrives with priority 5, no preemption occurs. Context switching introduces overhead; the running process continues under the FCFS tie-breaking rule.
- Confusing Aging with Dynamic Priority: While aging is a form of dynamic priority adjustment, general dynamic priority may fluctuate based on I/O burst ratios or CPU consumption. Aging strictly moves in the direction that increases dispatch urgency to eliminate starvation.