Question

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.

Official answer and solution
Official answer
3
From
Official GATE 2017 answer key

Solution

Simulate preemptive Shortest Remaining Time First (SRTF) CPU scheduling to compute the completion time, turnaround time, and waiting time for each process.

We are given four processes:

  • P1: Arrival = 0, Burst = 7
  • P2: Arrival = 3, Burst = 3
  • P3: Arrival = 5, Burst = 5
  • P4: Arrival = 6, Burst = 2

Trace the scheduling step by step:

  • At t=0t = 0: Only P1 is available (remaining burst = 7). P1 runs from t=0t = 0 to t=3t = 3.
  • At t=3t = 3: P1 has remaining burst 7−3=47 - 3 = 4. P2 arrives with burst 3. Since 3<43 < 4, P2 preempts P1. P2 runs.
  • At t=5t = 5: P2 has remaining burst 3−2=13 - 2 = 1. P3 arrives with burst 5. Remaining times: P2 = 1, P1 = 4, P3 = 5. P2 continues running.
  • At t=6t = 6: P2 completes (completion time = 6). P4 arrives with burst 2. Remaining times: P4 = 2, P1 = 4, P3 = 5. P4 has the shortest remaining time, so P4 runs from t=6t = 6 to t=8t = 8.
  • At t=8t = 8: P4 completes (completion time = 8). Remaining processes: P1 (rem = 4), P3 (rem = 5). P1 runs from t=8t = 8 to t=12t = 12.
  • At t=12t = 12: P1 completes (completion time = 12). Only P3 remains (rem = 5). P3 runs from t=12t = 12 to t=17t = 17.
  • At t=17t = 17: P3 completes.

Calculate turnaround and waiting times (Waiting time = Turnaround time - Burst time):

  • P1: Turnaround = 12−0=1212 - 0 = 12, Waiting = 12−7=512 - 7 = 5
  • P2: Turnaround = 6−3=36 - 3 = 3, Waiting = 3−3=03 - 3 = 0
  • P3: Turnaround = 17−5=1217 - 5 = 12, Waiting = 12−5=712 - 5 = 7
  • P4: Turnaround = 8−6=28 - 6 = 2, Waiting = 2−2=02 - 2 = 0

Average waiting time across all 4 processes:

Average Waiting Time=5+0+7+04=124=3.0 ms\text{Average Waiting Time} = \frac{5 + 0 + 7 + 0}{4} = \frac{12}{4} = 3.0 \text{ ms}
Final answer

3.0

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 1
Question
24 of 65, printed as CS Q.24
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.