SJF, SRTF & Priority Scheduling: Optimal Turnaround & Starvation
“Non-preemptive SJF, preemptive SRTF (optimal waiting time), Priority scheduling, and Aging.”
1.Shortest Job First (SJF): Principle & Theoretical Optimality
§ 3.1.Shortest Job First (SJF) associates with each process the length of its next CPU burst. When the CPU becomes available, it is assigned to the process that has the smallest burst time. If two processes have identical burst lengths, FCFS scheduling is used as a tiebreaker.
Provable Optimality: SJF is provably optimal in giving minimum average waiting time for a given set of stationary processes. Moving a short process before a long one reduces the waiting time of the short process by more than it increases the waiting time of the long one.
The Fundamental Limitation: SJF cannot be implemented in general-purpose long-term/short-term schedulers because the Operating System cannot predict the exact future CPU burst length of a user process.
Burst Prediction via Exponential Smoothing: The OS approximates the next burst \tau_{n+1} using historical actual bursts t_n and prior estimates \tau_n: \tau_{n+1} = \alpha \cdot t_n + (1 - \alpha) \cdot \tau_n, where 0 ≤ \alpha ≤ 1 (typically \alpha = 0.5).
In GATE multiple-choice questions, remember: Non-preemptive SJF is optimal among non-preemptive algorithms, whereas Preemptive SJF (SRTF) is optimal among ALL scheduling algorithms for minimizing average waiting time.
2.Shortest Remaining Time First (SRTF): Preemptive Scheduling
§ 3.2.SRTF is the preemptive version of SJF. When a new process arrives at the Ready Queue with a remaining CPU burst time strictly shorter than the currently running process's remaining time, the running process is preempted and moved back to the Ready Queue.
Key GATE Preemption Condition: Preemption occurs IF AND ONLY IF Remaining_Time(New) < Remaining_Time(Current). If Remaining_Time(New) Remaining_Time(Current)==, the CPU continues running the current process to avoid unnecessary context-switch overhead.
Trade-off: While SRTF yields the lowest theoretical average waiting time, every preemption incurs a CPU context switch. In practice, high context-switch frequency degrades effective throughput.
3. Algorithm Comparison Matrix
Detailed algorithmic trade-offs across preemption, optimality, starvation risk, and typical use cases:
| Feature / Aspect | Algorithm | Preemptive? |
|---|---|---|
| FCFS | No | Fairness / Simplicity |
| SJF (Non-preemptive) | No | Avg WT (Non-preemptive) |
| SRTF (Preemptive) | Yes | Avg WT (Overall) |
| Round Robin (RR) | Yes (Time Quantum) | Response Time |
| Priority Scheduling | Both (Preemptive & Non) | Importance / Urgency |
4. GATE Step-by-Step Numerical: SRTF Gantt Chart & Turnaround Time
| P1AT = 0, BT = 8 | P2AT = 1, BT = 4 | P3AT = 2, BT = 9 | P4AT = 3, BT = 5 |
• At t = 0: Only P1 is available. P1 executes from t = 0 to 1. • At t = 1: P2 arrives (BT = 4). P1 has remaining burst = 7. Since 4 < 7, P1 is preempted. P2 takes CPU. • At t = 2: P3 arrives (BT = 9). P2 has remaining burst = 3. Since 3 < 9, P2 continues. • At t = 3: P4 arrives (BT = 5). P2 has remaining burst = 2. Since 2 < 5, P2 continues. • At t = 5: P2 completes execution! Completion Time CT(P2) = 5.
• At t = 5: Ready queue holds P1(rem = 7), P4(rem = 5), P3(rem = 9). Smallest remaining burst is P4 (5). P4 executes from t = 5 to 10. CT(P4) = 10. • At t = 10: Ready queue holds P1(rem = 7) and P3(rem = 9). Smallest is P1 (7). P1 executes from t = 10 to 17. CT(P1) = 17. • At t = 17: Only P3 remains (BT = 9). P3 executes from t = 17 to 26. CT(P3) = 26.
• P1: TAT = 17 - 0 = 17, WT = 17 - 8 = 9 • P2: TAT = 5 - 1 = 4, WT = 4 - 4 = 0 • P3: TAT = 26 - 2 = 24, WT = 24 - 9 = 15 • P4: TAT = 10 - 3 = 7, WT = 7 - 5 = 2 Total TAT = 17 + 4 + 24 + 7 = 52. Average TAT = 52 / 4 = 13.0 units. Total WT = 9 + 0 + 15 + 2 = 26. Average WT = 26 / 4 = 6.5 units.
5.Priority Scheduling & The Aging Mitigation Strategy
§ 3.5.In Priority Scheduling, an integer priority is assigned to each process. By standard UNIX convention, smaller integer values indicate higher priority (e.g., priority 0 is higher than priority 10). The CPU is allocated to the process with the highest priority.
Starvation (Indefinite Blocking): A major hazard where low-priority processes may wait indefinitely if there is a steady stream of higher-priority processes.
The Solution — Aging: Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time. For example, if priorities range from 127 (lowest) to 0 (highest), the kernel can decrement the priority value by 1 every 15 minutes of ready-queue waiting. Eventually, even the lowest-priority process climbs to the top.
6. 1-Minute Panic Revision
“SJF minimizes average waiting time (provably optimal). SRTF is preemptive SJF. Priority scheduling requires aging to prevent starvation.”
- •Exponential Smoothing: tau_(n+1) = alpha t_n + (1 - alpha) tau_n.
- •TAT = CT - AT; WT = TAT - BT.
- •SRTF re-evaluates scheduling whenever a new process arrives with remaining burst < current process.
- •SJF is provably optimal for average waiting time among all non-preemptive algorithms, but cannot be implemented without predicting future burst time.
- •Priority Inversion: High priority process blocked waiting for resource held by low priority process. Fixed by Priority Inheritance Protocol (PIP).
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Official slides covering mathematical proof of SJF optimality, exponential smoothing, and priority aging.
Clear proof of why Shortest Time-to-Completion First (STCF/SRTF) minimizes average turnaround time.
If the textbook derivation did not click immediately, consult these targeted video lessons:
Step-by-step Gantt chart solving with detailed calculations of CT, TAT, and WT under arrival preemption.
Covers high-yield GATE traps: handling ties, priority inversion, and using aging to eliminate starvation.
Curated lectures on Gantt Charts, Preemption, FCFS Convoy Effect, Round Robin Quantum & SJF/SRTF:
Step-by-step Gantt chart calculations with zero arithmetic ambiguity.
The most reliable demonstration of ready-queue tracking during simultaneous arrivals.
Structured textbook-level coverage with cleanly paced whiteboard walkthroughs.
Intense numerical speed practice and identifying examiner traps in Gantt charts.