SRTF Scheduling: Shortest Remaining Time First
Shortest Remaining Time First (SRTF) runs the eligible process with the least CPU work still unfinished. It is preemptive: a new arrival can interrupt the current process when the newcomer needs strictly less work than the current process has left.
The rule
Remaining work is the original burst minus service already received. Comparing the original bursts after a process has run would apply the wrong rule. In this simulator, an equal remaining value does not force the running process to yield.
Worked example
| Process | Arrival | Burst |
|---|---|---|
| P1 | 0 | 7 |
| P2 | 1 | 3 |
| P3 | 2 | 1 |
One CPU · One burst per process · No I/O · Dispatch cost 0. Times are abstract units.
At 1, P2 needs 3 units, strictly less than P1's 6 remaining. It interrupts the incumbent; unfinished work is retained.
At 2, P3 needs 1 units, strictly less than P2's 2 remaining. It interrupts the incumbent; unfinished work is retained.
The full CPU trace is P1 [0, 1), P2 [1, 2), P3 [2, 3), P2 [3, 5), P1 [5, 11).
Strictly shorter remaining work takes the CPU.
Strictly shorter remaining work takes the CPU.
- P1: [0, 1)
- P2: [1, 2)
- P3: [2, 3)
- P2: [3, 5)
- P1: [5, 11)
Calculate the result
| Process | Completion | Waiting | Turnaround | Response |
|---|---|---|---|---|
| P1 | 11 | 4 | 11 | 0 |
| P2 | 5 | 1 | 4 | 0 |
| P3 | 3 | 0 | 1 | 0 |
P1: turnaround = 11 − 0 = 11. Waiting = 11 − 7 = 4. First response = 0 − 0 = 0.
First response measures only the first service. Waiting also includes later periods when this process is ready but another process owns the CPU.
Mean waiting = (4 + 1 + 0) / 3 ≈ 1.667 units. Mean response = 0 units.
The tradeoff
SRTF gives short remaining work quick access, but long work can be delayed by later short arrivals. It also needs known or estimated service lengths. More process changes can add overhead when dispatch cost is nonzero; the zero-cost example isolates the selection rule.