Answer: 2
We schedule the processes using preemptive Shortest Remaining Time First (SRTF) scheduling. Let us trace the execution from t=0:
- At t=0: Only P1 is available. It starts executing.
- At t=1: P2 arrives with a burst time of 1 ms. The remaining burst time of P1 is 2 ms. Since 1<2, P2 preempts P1 and runs till completion at t=2.
- At t=2: P1 resumes execution.
- At t=3: P3 arrives with a burst time of 3 ms. The remaining burst time of P1 is 1 ms. Since 1<3, P1 continues execution till completion at t=4.
At t=4, P1 and P2 are completed. Let us calculate their waiting times (WT):
- WT(P1)=Completion Time−Arrival Time−Burst Time=4−0−3=1 ms
- WT(P2)=2−1−1=0 ms
We are given that the average waiting time of all four processes is 1 ms. Therefore, the total waiting time is:
Total WT=1×4=4 ms
WT(P1)+WT(P2)+WT(P3)+WT(P4)=4⟹1+0+WT(P3)+WT(P4)=4
WT(P3)+WT(P4)=3 ms
At t=4, the remaining processes are P3 (burst time = 3) and P4 (burst time = Z).
- If Z≥3, P3 executes first from t=4 to t=7, and then P4 executes. This gives WT(P3)=7−3−3=1 ms and WT(P4)=(7+Z)−4−Z=3 ms. The sum of their waiting times would be 1+3=4 ms, which is incorrect.
- If Z<3, P4 executes first from t=4 to t=4+Z, and then P3 executes from t=4+Z to t=7+Z. This gives:
- WT(P4)=(4+Z)−4−Z=0 ms
- WT(P3)=(7+Z)−3−3=Z+1 ms
Setting the sum of waiting times to 3:
0+(Z+1)=3⟹Z=2
Since Z=2 satisfies the condition Z<3, the value of Z is 2.