# SRTF (Shortest Remaining Time First) Scheduling

> Shortest Remaining Time First (SRTF) scheduling is the preemptive version of SJF, always running the ready process with the least remaining burst time. When a new process arrives with a burst time shorter than the time left on the running process, the scheduler preempts immediately, which minimizes average waiting time even more than non-preemptive SJF.

Canonical: https://devsunite.com/resources/core-subjects/operating-systems/srtf-scheduling
Last updated: 2026-11-22

Subject: Operating Systems · Category: Process Scheduling · 4 min read

Shortest Remaining Time First (SRTF) is the preemptive counterpart to SJF (covered in its own dedicated topic). Where non-preemptive SJF picks the shortest job available and lets it run uninterrupted to completion, SRTF constantly re-evaluates: any time a new process arrives, if that new process's total burst time is shorter than the *remaining* time left on whatever's currently running, the scheduler immediately preempts the running process and switches to the new, shorter one.

## How it works

Every time a new process enters the ready queue, compare its burst time against the remaining burst time of the currently-executing process. If the new arrival is shorter, preempt immediately and switch to it. Otherwise, keep running the current process. This makes SRTF the truly optimal algorithm for minimizing average waiting time, even more so than non-preemptive SJF, since it can react to a newly-arrived short job immediately rather than waiting for the current process to finish first.

## A worked example

Three processes:

| Process | Arrival Time | Burst Time |
|---------|---------------|------------|
| P1 | 0 | 8 |
| P2 | 1 | 4 |
| P3 | 2 | 2 |

At time 0, only P1 exists, so it starts running. At time 1, P2 arrives with burst time 4. P1 has been running for 1 unit, so its remaining time is 8 - 1 = 7. Since P2's 4 is shorter than P1's remaining 7, preempt P1 and switch to P2.

At time 2, P3 arrives with burst time 2. P2 has run for 1 unit (from time 1 to 2), so its remaining time is 4 - 1 = 3. P3's own burst time is 2, shorter than P2's remaining 3, so preempt P2 and switch to P3.

P3 runs from time 2 to 4 (its full 2 units, uninterrupted, since nothing shorter arrives during that window). At time 4, resume P2, which has 3 units remaining, running from 4 to 7. At time 7, resume P1, which has 7 units remaining, running from 7 to 14.

Execution order: P1 (0-1), P2 (1-2), P3 (2-4), P2 (4-7), P1 (7-14). Notice P1 and P2 both got interrupted and resumed later, exactly the preemptive behavior that distinguishes SRTF from plain SJF.

## Where this matters in real systems

Pure SRTF isn't implemented literally in general-purpose OS schedulers, since it requires knowing (or predicting) burst times in advance, the same practical limitation SJF has. Its real influence shows up conceptually in interactive schedulers that give preferential, immediate treatment to processes that appear to need very little CPU time (a common heuristic: a process that's mostly been sleeping/waiting on I/O is assumed to be short/interactive when it does wake up and is favored accordingly), which is philosophically the same instinct SRTF formalizes: favor whatever looks shortest right now, even if it means interrupting something already running.

## What interviewers actually ask about SRTF

- **"What's the difference between SJF and SRTF?"** SJF (non-preemptive) lets a running process finish once started; SRTF can preempt a running process the instant a shorter job arrives, comparing against the running process's *remaining* time, not its original total burst time.
- **"Why is SRTF considered even more optimal than non-preemptive SJF for average waiting time?"** Because it can react immediately to a newly-arrived short process instead of waiting for the current process to finish or block first.
- **"What real-world limitation does SRTF share with SJF?"** Both require knowing (or accurately predicting) burst time in advance, which real, general-purpose workloads usually can't provide.
- **"Trace through what happens if a shorter process arrives while another is running."** The scheduler compares the new arrival's burst time to the running process's remaining time; if shorter, it immediately preempts the running process and switches.

## Key takeaways

- SRTF is the preemptive version of SJF, comparing new arrivals against the currently-running process's remaining time, not its original total.
- It preempts immediately whenever a shorter job arrives, making it even more optimal for average waiting time than non-preemptive SJF.
- Like SJF, it requires knowing burst times in advance, which limits its use as a literal, direct implementation in general-purpose schedulers.
- Its underlying philosophy, favor whatever looks shortest right now, echoes in real interactive-scheduling heuristics.

## Related

- [Previous: Shortest Job First (SJF) Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/sjf-scheduling)
- [Next: Priority Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/priority-scheduling)
- [More in Process Scheduling: Process Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/process-scheduling)
- [More in Process Scheduling: Scheduling Queues](https://devsunite.com/resources/core-subjects/operating-systems/scheduling-queues)
- [More in Process Scheduling: Preemptive vs Non-Preemptive Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/preemptive-vs-non-preemptive-scheduling)
- [More in Process Scheduling: Scheduler vs Dispatcher](https://devsunite.com/resources/core-subjects/operating-systems/scheduler-vs-dispatcher)
- [More in Process Scheduling: Scheduling Criteria](https://devsunite.com/resources/core-subjects/operating-systems/scheduling-criterias)
- [More in Process Scheduling: FCFS (First Come First Served) Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/fcfs-scheduling)
- [More in Process Scheduling: Round Robin Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/round-robin-scheduling)
- [More in Process Scheduling: Multilevel Queue Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/multilevel-queue-scheduling)
- [More in Process Scheduling: Multilevel Feedback Queue Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/multilevel-feedback-queue-scheduling)
- [More in Process Scheduling: Starvation and Aging in Scheduling](https://devsunite.com/resources/core-subjects/operating-systems/starvation-and-aging)
- [All 205 OS interview questions](https://devsunite.com/resources/core-subjects/operating-systems)
