SRTF Scheduling — Shortest Remaining Time First
Press Next → or use ← → arrow keys
The Story That Explains SRTF
That is SRTF: always give the CPU to the job with the shortest remaining time, even if it means interrupting one already in progress.
SRTF is the preemptive version of SJF. Where SJF only chooses when the CPU falls idle, SRTF re-evaluates the instant a new process arrives — and will preempt the running job if the newcomer's burst is shorter than what's left of the current one.
Where SRTF Sits in the Family
Non-preemptive schedulers (FCFS, SJF, non-preemptive Priority) never interrupt a running job. Preemptive ones — SRTF, Round Robin, preemptive Priority, MLFQ — can. SRTF is simply SJF that's allowed to interrupt.
The SRTF Algorithm — Step by Step
The scheduler does not re-sort every clock tick — only when a process arrives
or the current one completes. Those are the only two moments the decision can change. Metrics
are the same as always: TAT = CT − AT, WT = TAT − BT.
The Classic Galvin Problem
| Proc | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 8 | 17 | 17 | 9 |
| P2 | 1 | 4 | 5 | 4 | 0 |
| P3 | 2 | 9 | 26 | 24 | 15 |
| P4 | 3 | 5 | 10 | 7 | 2 |
| Averages → | 13.00 | 6.50 | |||
P1 starts, is preempted by P2 at t=1, and only resumes at t=10 after P2 and P4 clear. Completion times
come straight off the chart; then TAT = CT − AT and WT = TAT − BT.
Avg WT = 6.50 units.
The Second-by-Second Decisions
Every decision above happens at an arrival or a completion — never in between. That's what keeps SRTF tractable to solve by hand: you only redraw the queue at those moments.
Ties & Two Sharp Preemptions
| Proc | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 7 | 16 | 16 | 9 |
| P2 | 2 | 4 | 7 | 5 | 1 |
| P3 | 4 | 1 | 5 | 1 | 0 |
| P4 | 5 | 4 | 11 | 6 | 2 |
| Averages → | 7.00 | 3.00 | |||
P1 is preempted by P2 at t=2, then P2 is immediately preempted by the tiny P3 (burst 1) at t=4. After P3 finishes, P2 resumes, then P4, then P1 — the longest — runs last. Avg WT = 3.00 units.
Real Scenario — A Bank Server
| Request | Task | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|---|
| P1 | Balance query | 0 | 6 | 12 | 12 | 6 |
| P2 | UPI transfer | 1 | 3 | 4 | 3 | 0 |
| P3 | Statement PDF | 2 | 8 | 20 | 18 | 10 |
| P4 | Login OTP | 3 | 2 | 7 | 4 | 2 |
| P5 | Card block | 4 | 1 | 5 | 1 | 0 |
| Averages → | 7.60 | 3.60 | ||||
The one-off card-block (P5·1) and OTP (P4·2) slip through quickly while the big statement PDF (P3·8) waits — exactly what you want on an interactive server. Avg WT = 3.60 ms.
SRTF vs FCFS vs SJF — Head to Head
| Property | FCFS | SJF (non-preempt) | SRTF (preempt) |
|---|---|---|---|
| Preemption | No | No | Yes |
| Average WT | Worst | Better | Best |
| Starvation risk | None | Possible | High for long jobs |
| Overhead | Zero | Low | High — context switches |
| Needs burst estimate | No | Yes | Yes |
| Convoy effect | Yes | No | No |
| Best for | Batch, simple | Batch, known burst | Short interactive jobs |
Advantages & Disadvantages
Burst Prediction — The Missing Piece
Since a burst can't truly be known ahead of time, the OS predicts it:
τₙ₊₁ = α·tₙ + (1 − α)·τₙ — blend the actual last burst tₙ with the
previous prediction τₙ. With α = 0.5 both count equally.
| Cycle | Actual tₙ | Predicted τₙ | τₙ₊₁ = 0.5·tₙ + 0.5·τₙ |
|---|---|---|---|
| 0 | — | 10 | — |
| 1 | 6 | 10 | 8 |
| 2 | 4 | 8 | 6 |
| 3 | 6 | 6 | 6 |
| 4 | — | 6 | 6 (stabilises) |
The prediction absorbs one-off blips but still follows a genuine change in a process's behaviour — giving SRTF a usable estimate of "remaining time" without a crystal ball.
Solving Starvation — Aging
Because SRTF always favours the shortest remaining time, a long job can be shoved aside every time a shorter one arrives. Under a steady stream of short jobs, that long job may never run — it starves.
effective_RT = remaining − aging_factor × wait_timeAging keeps SRTF's short-job responsiveness while guaranteeing that long jobs make progress. It's the same fix used for priority scheduling's starvation problem.
Seven Rules for Solving SRTF
Shortest Remaining Time First — Mastered
Track remaining times, redraw the queue at each arrival and completion, mark every preemption, and read the metrics off the finished Gantt chart. You've seen a single preemption, a double preemption, and a real interactive workload.
Next up: Round Robin (fair time-slicing regardless of burst) and Priority Scheduling (with aging to prevent starvation). Compare each against this SRTF baseline for waiting time and responsiveness.
🚑 End of tutorial · Press ← to review, or click Restart