Related Articles
GATE | GATE-CS-2007 | Question 85
• Last Updated : 14 Feb, 2018

An operating system uses Shortest Remaining Time first (SRT) process scheduling algorithm. Consider the arrival times and execution times for the following processes:

```Process  Execution time  Arrival time
P1             20            0
P2             25            15
P3             10            30
P4             15            45```

What is the total waiting time for process P2?
(A) 5
(B) 15
(C) 40
(D) 55

Explanation:
Shortest remaining time, also known as shortest remaining time first (SRTF), is a scheduling method that is a pre-emptive version of shortest job next scheduling. In this scheduling algorithm, the process with the smallest amount of time remaining until completion is selected to execute. Since the currently executing process is the one with the shortest amount of time remaining by definition, and since that time should only reduce as execution progresses, processes will always run until they complete or a new process is added that requires a smaller amount of time.

The Gantt chart of execution of processes:

At time 0, P1 is the only process, P1 runs for 15 time units.
At time 15, P2 arrives, but P1 has the shortest remaining time. So P1 continues for 5 more time units.
At time 20, P2 is the only process. So it runs for 10 time units.
at time 30, P3 is the shortest remaining time process. So it runs for 10 time units.
at time 40, P2 runs as it is the only process. P2 runs for 5 time units.
At time 45, P3 arrives, but P2 has the shortest remaining time. So P2 continues for 10 more time units. P2 completes its execution at time 55.

As we know, turn around time is total time between submission of the process and its completion. Waiting time is the time The amount of time that is taken by a process in ready queue and waiting time is the difference between Turn around time and burst time.
Total turnaround time for P2 = Completion time – Arrival time
= 55 – 15 = 40
Total Waiting Time for P2= turn around time – Burst time
= 40 – 25 = 15
See question 3 of http://www.geeksforgeeks.org/operating-systems-set-12/

This solution is contributed by Nitika Bansal

Quiz of this Question

My Personal Notes arrow_drop_up