Question

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

Process Arrival time CPU burst time
P1 0 3
P2 1 1
P3 3 3
P4 4 Z

These processes are run on a single processor using preemptive Shortest Remaining Time First scheduling algorithm. If the average waiting time of the processes is 1 millisecond, then the value of ZZ is ________.

Official answer and solution
Official answer
2
From
Official GATE 2019 answer key

Solution

Construct the Gantt chart for Shortest Remaining Time First (SRTF) scheduling and solve for Z.

The processes, arrival times, and bursts are:

  • P1P_1: Arrival = 00, Burst = 33
  • P2P_2: Arrival = 11, Burst = 11
  • P3P_3: Arrival = 33, Burst = 33
  • P4P_4: Arrival = 44, Burst = ZZ

Let us trace SRTF scheduling step by step:

  • At t=0t = 0: Only P1P_1 has arrived (remaining burst = 33). P1P_1 starts execution.
  • At t=1t = 1: P2P_2 arrives with burst 11. P1P_1's remaining burst is 3−1=23 - 1 = 2. Since P2P_2's remaining burst (11) is less than P1P_1's (22), P1P_1 is preempted and P2P_2 runs.
  • At t=2t = 2: P2P_2 completes its burst of 11.
    • Completion time of P2=2P_2 = 2.
    • Turnaround time of P2=2−1=1P_2 = 2 - 1 = 1.
    • Waiting time of P2=1−1=0P_2 = 1 - 1 = 0.
      P1P_1 resumes with remaining burst 22.
  • At t=3t = 3: P3P_3 arrives with burst 33. P1P_1's remaining burst is 2−1=12 - 1 = 1. Since 1<31 < 3, P1P_1 continues.
  • At t=4t = 4: P1P_1 completes its burst.
    • Completion time of P1=4P_1 = 4.
    • Turnaround time of P1=4−0=4P_1 = 4 - 0 = 4.
    • Waiting time of P1=4−3=1P_1 = 4 - 3 = 1.

At t=4t = 4, P4P_4 arrives with burst ZZ. Ready queue holds P3P_3 (burst 33) and P4P_4 (burst ZZ).
We are given that the average waiting time is 1 ms1\text{ ms}:

WT(P1)+WT(P2)+WT(P3)+WT(P4)4=1  ⟹  1+0+WT(P3)+WT(P4)=4\frac{WT(P_1) + WT(P_2) + WT(P_3) + WT(P_4)}{4} = 1 \implies 1 + 0 + WT(P_3) + WT(P_4) = 4
WT(P3)+WT(P4)=3WT(P_3) + WT(P_4) = 3

If Z<3Z < 3, P4P_4 is dispatched before P3P_3:

  • P4P_4 runs from t=4t = 4 to 4+Z4 + Z. Completion time = 4+Z4 + Z.
    WT(P4)=(4+Z)−4−Z=0WT(P_4) = (4 + Z) - 4 - Z = 0
  • P3P_3 runs from t=4+Zt = 4 + Z to 7+Z7 + Z. Completion time = 7+Z7 + Z.
    WT(P3)=(7+Z)−3−3=1+ZWT(P_3) = (7 + Z) - 3 - 3 = 1 + Z

Sum of waiting times:

WT(P3)+WT(P4)=(1+Z)+0=3  ⟹  Z=2WT(P_3) + WT(P_4) = (1 + Z) + 0 = 3 \implies Z = 2

Checking consistency: Z=2<3Z = 2 < 3, so P4P_4 is indeed scheduled before P3P_3. Hence, Z=2Z = 2.

Final answer

2

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

Source

Paper
GATE 2019 Computer Science and Information Technology (CS)
Question
51 of 65, printed as CS Q.41
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.