SRTF Scheduling In OS
Shortest Remaining Time First (SRTF) scheduling is a preemptive CPU scheduling algorithm where any process which contains shortest remaining burst time is always executed first.

If a new process arrives which contains shorter remaining execution time than the currently running process, then the CPU switches to the new incoming process immediately.
| Note: Shortest Remaining Time First (SRTF) scheduling is also known as Shortest Job First (SJF) with preemption |
SRTF is designed to reduce the average waiting time and average turnaround time. It may cause starvation for long processes; therefore, it requires continuous monitoring of the ready queue.
How SRTF Scheduling Works
The working steps of SRTF scheduling are given below:
- Processes enter the ready queue according to their arrival time.
- The CPU selects the process with the shortest remaining burst time.
- The selected process starts executing.
- If a new process arrives with a shorter remaining burst time, the CPU switches to the new process; the current process is interrupted and returned to the ready queue.
- The CPU starts executing the new process.
- These steps continue until all processes finish execution.
Example of SRTF Scheduling
Consider there are 4 processes (P1, P2, P3, and P4) with their arrival and burst times, which are given in the following diagram
By using SRTF scheduling, calculate completion time (CT), waiting time (WT), turnaround time (TAT), average waiting time (AWT), average turnaround time (ATAT), and response time.
Solution
Here is the Gantt Chart of the given Example

All calculations of SRJF Example
The following diagram calculates completion time (CT), waiting time (WT), turnaround time (TAT), average waiting time (AWT), average turnaround time (ATAT), and response time.
Let’s explain the above example
At time 0
Only P1 arrives in the ready queue at time 0; no other process arrives yet. CPU will start execution with P1
- Ready Queue: P1
At time 1
P2 arrives, containing a burst time of 3 units of time, which is less than P1 (which contains burst time = 4, after executing 1 unit of time in the 0 to 1 period of time). So, the CPU switches to P2
- Ready Queue: P1, P2
At time 3, look at the Burst time of all processes
| Processes | Remaining Burst time |
|---|---|
| P1 | 4 |
| P2 | 3 |
At time 2
P3 arrives, which containing Burst time of 4 units of time, which is not the shortest burst time among others. So, the CPU continues with P2
- Ready Queue: P1, P2, P3
At time 2, look at the Burst time of all processes
| Processes | Remaining Burst time |
| P1 | 4 |
| P2 | 2 |
| P3 | 4 |
At time 3
No new process arrives; P2 Continues it’s execution
- Ready Queue: P1, P2, P3
At time 3, look at the Burst time of all processes
| Processes | Remaining Burst time |
| P1 | 4 |
| P2 | 1 |
| P3 | 4 |
At time 4
P2 completes its execution, and P4 arrives, which contains a burst time of 1 unit of time, which is the shortest burst time among others. So, the CPU switches to P4
- Ready Queue: P1, P3, P4
At time 4, look at the Burst time of all processes
| Processes | Remaining Burst time |
| P1 | 4 |
| P2 | Nil, Process Terminated |
| P3 | 4 |
| P4 | 1 |
At time 5
P4 completes its execution; no new process arrives. The ready queue contains only P1 and P3; both contain similar burst times, but P1 comes first, so it is executed first
- Ready Queue: P1, P3
At time 5, look at the Burst time of all processes
| Processes | Remaining Burst time |
| P1 | 4 |
| P2 | Nil, Process Terminated |
| P3 | 4 |
| P4 | Nil, Process Terminated |
At time 5 to 9:
P1 completes its execution; no new process arrives. The ready queue contains only P3; so it is executed
- Ready Queue: P3
At time 9, look at the Burst time of all processes
| Processes | Remaining Burst time |
| P1 | Nil, Process Terminated |
| P2 | Nil, Process Terminated |
| P3 | 4 |
| P4 | Nil, Process Terminated |
At time 9 to 13:
P3 completes its execution at 13; no new process arrives in time 9 to 13. The ready queue contains nothing.
- Ready Queue: empty
At time 13, look at the Burst time of all processes
| Processes | Remaining Burst time |
| P1 | Nil, Process Terminated |
| P2 | Nil, Process Terminated |
| P3 | Nil, Process Terminated |
| P4 | Nil, Process Terminated |
That’s all
Advantages of SRTF
Here are the top advantages of SRTF
- Minimum Average Waiting Time: SRTF provides the lowest average waiting time among CPU scheduling algorithms.
- Better CPU Utilization: Shorter processes finish quickly, improving overall system performance.
- Fast Response for Short Processes: Processes with small burst times receive the CPU sooner.
- Optimal Scheduling Algorithm: If burst times are known in advance, SRTF is considered an optimal scheduling algorithm.
Disadvantages of SRTF
Here are some disadvantages of SRTF
- Burst Time Must Be Known: SRTF is difficult to implement because the exact CPU burst time of each process is usually unknown.
- Starvation: Processes with long burst times may wait indefinitely if shorter processes keep arriving.
- High Context Switching: Frequent preemption increases the number of context switches, adding system overhead.
- Poor Response for Long Processes: Processes with larger burst times often experience longer waiting and response times.
- No Priority Support: SRTF schedules processes only by remaining burst time and does not consider process priorities.
Starvation in SRTF Scheduling
Starvation occurs when long processes continuously wait because new short processes keep arriving. Since SRTF always gives priority to the process with the shortest remaining time, a long process may be delayed for a very long time.
Example:
- P1 has a burst time of 30 ms.
- Small processes of 2 ms keep arriving.
- P1 is repeatedly interrupted.
- As a result, P1 waits much longer before completing.
Context Switching in SRTF
Context switching happens whenever the CPU stops executing one process and starts another.
In SRTF, context switching occurs frequently because every newly arrived shorter process can interrupt the currently running process. Although this improves response time, excessive context switching increases CPU overhead.
Difference Between SJF and SRTF
Here are some key differences between shortest job first (SJF) and shortest remaining time first (SRTF)
| Feature | SJF | SRTF |
|---|---|---|
| Scheduling Type | Non-preemptive | Preemptive |
| CPU Interruption | Not Allowed | Allowed |
| Decision Basis | Shortest burst time | Shortest remaining burst time |
| Response Time | Higher | Lower |
| Context Switching | Less | More |
| Average Waiting Time | Low | Usually lower than SJF |
