VOOZH about

URL: https://www.geeksforgeeks.org/operating-systems/shortest-remaining-time-first-srtf-with-predicted-time/

⇱ Shortest Remaining Time First (SRTF) With predicted Time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Shortest Remaining Time First (SRTF) With predicted Time

Last Updated : 26 Jul, 2025

CPU scheduling algorithms are essential components of operating systems that determine the order in which processes are executed on a computer's central processing unit (CPU). These algorithms aim to optimize CPU utilization, reduce waiting times, and enhance system performance by efficiently managing the execution of tasks in a multi-tasking environment. Various algorithms, such as First-Come, First-Served (FCFS), Shortest Job Next (SJN), Round Robin (RR), and Priority Scheduling, are employed to achieve these objectives, each with its own set of advantages and limitations. In this article, we study about Shortest Remaining Time First CPU Scheduling algorithm.

What is the SRTF Algorithm?

Shortest Remaining Time First (SRTF) is the preemptive version of the Shortest Job Next (SJN) algorithm, where the processor is allocated to the job closest to completion. It is also known as Shortest Job First with dynamic priority. It is a CPU scheduling algorithm of the Operating System.

In SRTF with predicted time, each process is assigned a priority based on its expected remaining burst time. The process with the highest priority (i.e., the shortest predicted remaining burst time) is selected to execute next. The predicted burst time is updated dynamically as the process runs, and the priority is recalculated based on the edited expected burst time.

Advantages of SRTF

The advantage of SRTF with predicted time is that:

  • It can reduce the number of preemptions and context switches, as processes with shorter predicted burst times will be given higher priority.
  • The accuracy of the predicted burst times can affect the performance of the algorithm, as inaccurate predictions can lead to poor scheduling decisions.

Disadvantages of SRTF

  • Shortest Remaining Time First (SRTF) is a CPU scheduling algorithm in which the process with the smallest remaining burst time is scheduled next. 
  • This algorithm can be impractical in certain scenarios, such as when the burst times of the processes are not known in advance or when there are frequent arrivals and departures of processes.

Pseudo Code

1. Initialize the ready queue with all the processes.
2. While the ready queue is not empty:
a. Find the process with the smallest predicted remaining burst time from the input.
b. Execute the process for a unit of time.
c. Update the predicted remaining burst time of the processes based on it's past execution history.
d. If the process has completed its execution, remove it from the ready queue.
e. If a new process arrives, add it to the ready queue.

C Program

Output

👁 Output_C
Output_C

C++ Code

Output

👁 Output_C++
Output_C++

Java Code

Output

Enter the number of processes: 3
Enter details for process 1
Process ID: 1
Arrival time: 0
Burst time: 3
Predicted time: 2
Enter details for process 2
Process ID: 3
Arrival time: 4
Burst time: 9
Predicted time: 6
Enter details for process 3
Process ID: 2
Arrival time: 4
Burst time: 10
Predicted time: 7

Process Arrival Time Burst Time Predicted Time Completion Time Turnaround Time Waiting Time
1 0 3 2 3 3 0
3 4 9 6 13 9 0
2 4 10 7 23 19 9

Average Turnaround Time: 10.333333333333334
Process ID: 4
Arrival time: 5
Burst time: 12
Predicted time: 9

Process Arrival Time Burst Time Predicted Time Completion Time Turnaround Time Waiting Time
1 0 5 4 5 5 0
2 3 9 6 14 11 2
3 4 10 7 24 20 10
4 5 12 9 36 31 19

Average Turnaround Time: 16.75
Average Waiting Time: 7.75

JavaScript Code

Output

[
Process {
id: 3,
arrivalTime: 4,
burstTime: 2,
predictedTime: 1,
remainingTime: -1
},
Process {
id: 2,
arrivalTime: 2,
burstTime: 4,
predictedTime: 2,
remainingTime: -4
},
Process {
id: 4,
arrivalTime: 5,
burstTime: 3,
predictedTime: 3,
remainingTime: -9
},
Process {
id: 1,
arrivalTime: 0,
burstTime: 6,
predictedTime: 4,
remainingTime: -1
}
]

Conclusion

In conclusion, SRTF is a CPU scheduling algorithm that prioritizes tasks based on their remaining execution time. It is an extension of the SJF algorithm and can reduce the average waiting time for all tasks. However, it requires knowledge of the remaining execution time of each task, which may not always be available, and the predicted execution times can be used as a solution for the program.

Comment