SRTF Scheduling

0
34

The Preemptive version of Shortest Job First(SJF) scheduling is known as Shortest Remaining Time First (SRTF). With the help of the SRTF algorithm, the process having the smallest amount of time remaining until completion is selected first to execute.

So basically in SRTF, the processes are scheduled according to the shortest remaining time:

However, the SRTF algorithm involves more overheads than the Shortest job first (SJF)scheduling, because in SRTF OS is required frequently in order to monitor the CPU time of the jobs in the READY queue and to perform context switching.

In the SRTF scheduling algorithm, the execution of any process can be stopped after a certain amount of time. On arrival of every process, the short-term scheduler schedules those processes from the list of available processes & running processes that have the least remaining burst time.

After all the processes are available in the ready queue, then, No preemption will be done and then the algorithm will work the same as SJF scheduling. In the Process Control Block, the context of the process is saved, when the process is removed from the execution and when the next process is scheduled. The PCB is accessed on the next execution of this process.

Advantages of SRTF

The main advantage of the SRTF algorithm is that it makes the processing of the jobs faster than the SJF algorithm, mentioned it’s overhead charges are not counted.

Disadvantages of SRTF

In SRTF, the context switching is done a lot more times than in SJN due to more consumption of the CPU’s valuable time for processing. The consumed time of CPU then adds up to its processing time and which then diminishes the advantage of fast processing of this algorithm.

Example

chart

Explanation

  • At the 0th unit of the CPU, there is only one process that is P1, so P1 gets executed for the 1 time unit.
  • At the 1st unit of the CPU, Process P2 arrives. Now, the P1 needs 6 more units more to be executed, and the P2 needs only 3 units. So, P2 is executed first by preempting P1.
  • At the 3rd unit of time, the process P3 arrives, and the burst time of P3 is 4 units which is more than the completion time of P2 that is 1 unit, so P2 continues its execution.
  • Now after the completion of P2, the burst time of P3 is 4 units that means it needs only 4 units for completion while P1 needs 6 units for completion.
  • So, this algorithm picks P3 above P1 due to the reason that the completion time of P3 is less than that of P1
  • P3 gets completed at time unit 8, there are no new processes arrived.
  • So again, P1 is sent for execution, and it gets completed at the 14th unit.