The GATE Grind

GATE 2017 CS – Question 34

Operating System · CPU and I/O Scheduling · 1 mark · Numerical answer

Consider the following CPU processes with arrival times (in milliseconds) and length of CPU bursts (in milliseconds) as given below:

ProcessArrival timeBurst time
P107
P233
P355
P462

If the pre-emptive shortest remaining time first scheduling algorithm is used to schedule the processes, then the average waiting time across all processes is ________ milliseconds.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 3

Explanation

P1 runs from 0. At time 3, P1 has 4 left and P2 needs 3, so P2 runs from 3 to 6. At 6, P4 (2) is shortest, so it runs 6 to 8. Then P1 (4 left) runs 8 to 12, and finally P3 runs 12 to 17. The waiting times are P1: $12 - 7 = 5$, P2: $6 - 3 - 3 = 0$, P3: $17 - 5 - 5 = 7$, P4: $8 - 6 - 2 = 0$. The average is $\frac{5 + 0 + 7 + 0}{4} = 3$.