Question

An operating system uses shortest remaining time first scheduling algorithm for pre-emptive scheduling of processes. Consider the following set of processes with their arrival times and CPU burst times (in milliseconds):

Process Arrival Time Burst Time
P1 0 12
P2 2 4
P3 3 6
P4 8 5

The average waiting time (in milliseconds) of the processes is _____.

Official answer and solution
Official answer
5.5
From
Official GATE 2014 answer key

Solution

Simulate preemptive Shortest Remaining Time First (SRTF) scheduling to build the Gantt chart and compute individual and average waiting times.

We trace execution cycle by cycle according to SRTF:

  • P1P_1: arrival 00, burst 1212
  • P2P_2: arrival 22, burst 44
  • P3P_3: arrival 33, burst 66
  • P4P_4: arrival 88, burst 55
  1. Gantt Chart Construction:

    • Time 00 to 22: Only P1P_1 is present. P1P_1 runs for 22 ms (remaining: 12−2=1012 - 2 = 10).
    • Time 22: P2P_2 arrives with burst 44. Since remaining time of P2P_2 (44) < remaining time of P1P_1 (1010), P1P_1 is preempted and P2P_2 runs.
    • Time 33: P3P_3 arrives with burst 66. P2P_2 has remaining 3<63 < 6, so P2P_2 continues.
    • Time 66: P2P_2 finishes (total run 44 ms). Ready queue: P3P_3 (burst 66), P1P_1 (remaining 1010). P3P_3 has shorter remaining time (6<106 < 10), so P3P_3 starts running.
    • Time 88: P4P_4 arrives with burst 55. At this instant, P3P_3 has run from 66 to 88 (22 ms), so P3P_3 has remaining time 6−2=46 - 2 = 4 ms. Since remaining time of P3P_3 (44) < burst of P4P_4 (55), P3P_3 is NOT preempted and continues running.
    • Time 1212: P3P_3 finishes (total run 66 ms). Ready queue: P4P_4 (remaining 55), P1P_1 (remaining 1010). P4P_4 runs (5<105 < 10).
    • Time 1717: P4P_4 finishes (total run 55 ms). P1P_1 resumes with remaining 1010 ms.
    • Time 2727: P1P_1 finishes.

    Gantt chart: P1 (0..2) | P2 (2..6) | P3 (6..12) | P4 (12..17) | P1 (17..27)

  2. Completion and Waiting Times:

    • P1P_1: Completion = 2727. Turnaround = 27−0=2727 - 0 = 27. Waiting time = 27−12=1527 - 12 = 15.
    • P2P_2: Completion = 66. Turnaround = 6−2=46 - 2 = 4. Waiting time = 4−4=04 - 4 = 0.
    • P3P_3: Completion = 1212. Turnaround = 12−3=912 - 3 = 9. Waiting time = 9−6=39 - 6 = 3.
    • P4P_4: Completion = 1717. Turnaround = 17−8=917 - 8 = 9. Waiting time = 9−5=49 - 5 = 4.
  3. Average Waiting Time:

    Average WT=15+0+3+44=224=5.5 ms.\text{Average WT} = \frac{15 + 0 + 3 + 4}{4} = \frac{22}{4} = 5.5\text{ ms}.
Final answer

5.5

Common trap

Preempting P3 at t = 8 by mistakenly comparing P4's burst (5) with P3's original burst (6) instead of P3's remaining burst (4).

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

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 3
Question
42 of 65, printed as CS Q.32
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.