Shortest Remaining Time First SRTF Scheduling Algorithm

For Complete YouTube Video: Click Here

In this class, we will try to understand Shortest Remaining Time First SRTF Scheduling Algorithm.

In our previous class, we have already explained the Shortest Job First SJF concept.

Shortest Remaining Time First SRTF Scheduling Algorithm

Shortest Remaining Time First SRTF Scheduling Algorithm will work the same as the shortest job first, but the only difference is the shortest remaining time first SRTF is preemptive.

To understand this, we will consider the example.

We considered the above example for the shortest job first and FCFS.

To solve the above example, we will consider the Gantt Chart.

From the above, we will consider P1 first because this is the only process.

Because the Shortest Remaining Time First SRTF Scheduling Algorithm is preemptive, we assume the preemption for every unit.

Now, P1 will be preempted after one unit, as shown below.

After one unit of time, the processes P1 and P2 are in the ready pool. The remaining time for P1 and P2 are 1 and 5.

Now, we will consider P1 as it has the shortest remaining time.

After three units of time, the processes P1, P2, and P3 are in the ready pool, and P1 completes its execution.

We will consider P3 as it has the shortest remaining time and completes its execution.

After three units of time, P1 and P3 complete their execution, and we have only P2 and P4 with 5 and 4 units of burst time.

As P4 has the shortest burst time, P4 will get executed for only one unit and the remaining time is three units.

After four units of time, we have the same P2 and P4 in the pool.

Again we will consider P2 as it has the shortest remaining time.

After five units of time, we have only P2, P4, and P5 in the pool with burst times 5, 2, and 3. By this time, all the processes have arrived in the ready pool.

Once all the processes have arrived, the Shortest Remaining Time First SRTF Scheduling Algorithm will behave like the Shortest job first non-preemptive way.

P2 has the shortest remaining time from the remaining processes, so P2 will be switched for execution and completes the execution.

Now, P5, with the shortest remaining time, will be switched and gets executed.

Next, P2 will get executed.

We will find all the respective times CT, TAT, and WT.