Skip to content
Official PYQ · 2019

GATE CS 2019 Q41 — CPU Scheduling

Explain with AI
Consider the following four processes with arrival times (in milliseconds) and their length of CPU bursts (in milliseconds) as shown below:
ProcessP1P2P3P4Arrival Time0134CPU burst time313Z\begin{array}{|c|c|c|c|c|} \hline \text{Process} & P1 & P2 & P3 & P4 \\ \hline \text{Arrival Time} & 0 & 1 & 3 & 4 \\ \hline \text{CPU burst time} & 3 & 1 & 3 & Z \\ \hline \end{array}
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 11 millisecond, then the value of ZZ is _____
View worked solution

Answer: 2

We schedule the processes using preemptive Shortest Remaining Time First (SRTF) scheduling. Let us trace the execution from t=0t = 0:

  • At t=0t = 0: Only P1P_1 is available. It starts executing.
  • At t=1t = 1: P2P_2 arrives with a burst time of 11 ms. The remaining burst time of P1P_1 is 22 ms. Since 1<21 < 2, P2P_2 preempts P1P_1 and runs till completion at t=2t = 2.
  • At t=2t = 2: P1P_1 resumes execution.
  • At t=3t = 3: P3P_3 arrives with a burst time of 33 ms. The remaining burst time of P1P_1 is 11 ms. Since 1<31 < 3, P1P_1 continues execution till completion at t=4t = 4.

At t=4t = 4, P1P_1 and P2P_2 are completed. Let us calculate their waiting times (WT):

  • WT(P1)=Completion Time−Arrival Time−Burst Time=4−0−3=1 ms\text{WT}(P_1) = \text{Completion Time} - \text{Arrival Time} - \text{Burst Time} = 4 - 0 - 3 = 1\text{ ms}
  • WT(P2)=2−1−1=0 ms\text{WT}(P_2) = 2 - 1 - 1 = 0\text{ ms}

We are given that the average waiting time of all four processes is 11 ms. Therefore, the total waiting time is:

Total WT=1×4=4 ms\text{Total WT} = 1 \times 4 = 4\text{ ms} WT(P1)+WT(P2)+WT(P3)+WT(P4)=4  ⟹  1+0+WT(P3)+WT(P4)=4\text{WT}(P_1) + \text{WT}(P_2) + \text{WT}(P_3) + \text{WT}(P_4) = 4 \implies 1 + 0 + \text{WT}(P_3) + \text{WT}(P_4) = 4 WT(P3)+WT(P4)=3 ms\text{WT}(P_3) + \text{WT}(P_4) = 3\text{ ms}

At t=4t = 4, the remaining processes are P3P_3 (burst time = 33) and P4P_4 (burst time = ZZ).

  • If Z≥3Z \ge 3, P3P_3 executes first from t=4t = 4 to t=7t = 7, and then P4P_4 executes. This gives WT(P3)=7−3−3=1 ms\text{WT}(P_3) = 7 - 3 - 3 = 1\text{ ms} and WT(P4)=(7+Z)−4−Z=3 ms\text{WT}(P_4) = (7+Z) - 4 - Z = 3\text{ ms}. The sum of their waiting times would be 1+3=4 ms1 + 3 = 4\text{ ms}, which is incorrect.
  • If Z<3Z < 3, P4P_4 executes first from t=4t = 4 to t=4+Zt = 4+Z, and then P3P_3 executes from t=4+Zt = 4+Z to t=7+Zt = 7+Z. This gives:
    • WT(P4)=(4+Z)−4−Z=0 ms\text{WT}(P_4) = (4+Z) - 4 - Z = 0\text{ ms}
    • WT(P3)=(7+Z)−3−3=Z+1 ms\text{WT}(P_3) = (7+Z) - 3 - 3 = Z + 1\text{ ms}
    Setting the sum of waiting times to 33: 0+(Z+1)=3  ⟹  Z=20 + (Z + 1) = 3 \implies Z = 2

Since Z=2Z = 2 satisfies the condition Z<3Z < 3, the value of ZZ is 22.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore CPU Scheduling questions