Type a branch, a subject or a topic — “round robin”, “paging”, “civil”.

Shortest Remaining Time First (SRTF)

SJF with preemption: a shorter job arriving takes the CPU away.

Skip to the animation

Shortest Remaining Time First is preemptive SJF: whenever a process arrives whose burst is shorter than what the running process has left, the CPU is taken away and given to the newcomer.

How it works

The scheduler keeps a remaining time for every process, not just a burst. Two things can trigger a decision:

  • The running process finishes — pick whichever ready process has the least remaining time.
  • A new process arrives — compare its burst to the running process's *remaining* time. If it is smaller, preempt immediately.

That second rule is the only difference from SJF, and it is why SRTF is also called preemptive SJF. It has the same optimality property, now over arrivals spread through time: no scheduler achieves a lower average waiting time.

Worked comparison

Four processes arriving at 0, 1, 2 and 3 with bursts 8, 4, 9 and 5 — the classic textbook input, and the one animated below:

SchedulerAverage waitingAverage turnaround
SJF (non-preemptive)7.7514.25
SRTF (preemptive)6.5013.00

The gain comes from one moment: at t = 1, P2 arrives needing 4 while P1 still has 7 left. SJF is powerless — P1 already has the CPU. SRTF switches, and P2 finishes at t = 5 instead of t = 12.

The vocabulary

Arrival time
When the process shows up in the ready queue. The scheduler cannot pick something that has not arrived yet — that single rule decides most exam answers.
Burst time
How long this process needs the CPU for, uninterrupted, before it would block or finish. Also called CPU burst.
Ready queue
Every process that could run right now but does not have the CPU. Scheduling is entirely the question of who gets pulled out of here next.
Preemptive vs non-preemptive
A non-preemptive scheduler cannot take the CPU back — once dispatched, a process runs until it blocks or finishes. A preemptive one can interrupt it mid-burst.
Context switch
Saving one process's registers and loading another's. Pure overhead: real work stops while it happens, typically a few microseconds.
Starvation
A process that stays runnable but never gets picked, because something more attractive keeps arriving. The classic fix is ageing — slowly raising the priority of anything that has waited a long time.

What it costs

Preemption is not free. Every switch is a context switch, and SRTF can switch on every arrival. On a workload with many short arrivals the overhead is real, and the running process's cache working set is thrown away each time.

Starvation is also worse than under SJF: a long job can be preempted repeatedly, having made progress it now has to sit on. As always, the fix is ageing.

The numbers you will be asked for

Turnaround time

completion − arrival

Total time the process spent in the system, from the moment it arrived to the moment it finished.

Waiting time

turnaround − burst

The part of that which was pure waiting. It is the only part a scheduler can actually change — the burst is fixed work.

Response time

first run − arrival

How long until the process gets the CPU for the first time. This is what an interactive user actually feels.

Throughput

processes ÷ total time

How much work the machine completes per unit of time.

Advantages and disadvantages

Advantages

  • The lowest average waiting time of any scheduling algorithm, preemptive or not.
  • Short jobs get served almost immediately, however busy the machine is.
  • Responds to arrivals instantly rather than waiting for the current burst to end.

Disadvantages

  • Still needs burst lengths in advance — the same impossible requirement as SJF.
  • Many more context switches, each one pure overhead plus lost cache warmth.
  • Long jobs starve more readily than under SJF, and lose progress-adjacent cache state each time.
  • Bookkeeping is heavier: remaining time must be tracked and compared on every arrival.

Watch it work

loading visualisation…

Check yourself

question 1 / 4

One question at a time. Pick an answer to see why it is right or wrong, then move on — there is no score to keep and nothing is saved.

When does an SRTF scheduler make a decision?
P1 arrives at 0 with burst 8 and starts running. P2 arrives at 1 with burst 4. What happens at time 1?
Compared with non-preemptive SJF, SRTF gives:
Why is SRTF impractical as a general-purpose scheduler despite being optimal?

0 / 4

4 still unanswered — the dots above jump straight to them.