Shortest Remaining Time First (SRTF)
You'll learn how SRTF dynamically switches to shorter jobs mid-execution for optimal average waiting time.
What Is SRTF?
Shortest Remaining Time First (SRTF) is the preemptive version of Shortest Job First (SJF) scheduling. While SJF picks the shortest job at scheduling time and runs it to completion, SRTF continuously monitors all processes and switches to whichever one has the least remaining burst time—even if that means interrupting the currently running process.
Think of it like a doctor's office that always sees the patient with the quickest appointment next. If you're mid-checkup but someone walks in needing just 30 seconds, the doctor might ask you to wait and handle them first to minimize everyone's average wait.
How It Works
When a new process arrives in the ready queue, SRTF compares its burst time against the remaining burst time of the currently running process. If the newcomer needs less time to complete, the scheduler preempts the current process (saving its state via context switch) and starts the shorter one immediately.
This approach guarantees the optimal average waiting time among all scheduling algorithms because it always prioritizes finishing quick tasks first, preventing them from queuing behind longer ones.
The Trade-Off
While mathematically optimal for average waiting time, SRTF has practical downsides:
- Requires knowing or estimating future CPU burst times
- Frequent context switches add overhead
- Can cause starvation for long processes if short ones keep arriving
Key Takeaway:
SRTF is the preemptive SJF algorithm that switches to any process with shorter remaining time, achieving the best possible average waiting time at the cost of potential starvation and context-switch overhead.