GATE CS 2025 Set 1 | Question 38
A computer has two processors, \(M_1\) and \(M_2\). Four processes \(P_1, P_2, P_3, P_4\) with CPU bursts of 20, 16, 25, and 10 milliseconds, respectively, arrive at the same time and these are the only processes in the system. The scheduler uses non-preemptive priority scheduling, with priorities decided as follows:
- \(M_1\) uses priority of execution for the processes as, \(P_1 \gt P_3 \gt P_2 \gt P_4\), i.e., \(P_1\) and \(P_4\) have highest and lowest priorities, respectively.
- \(M_2\) uses priority of execution for the processes as, \(P_2 \gt P_3 \gt P_4 \gt P_1\), i.e., \(P_2\) and \(P_1\) have highest and lowest priorities, respectively.
A process \(P_i\) is scheduled to a processor \(M_k\), if the processor is free and no other process \(P_j\) is waiting with higher priority. At any given point of time, a process can be allocated to any one of the free processors without violating the execution priority rules. Ignore the context switch time. What will be the average waiting time of the processes in milliseconds?
Explanation
Answer: (A)
Simulate both processors. Whenever a processor becomes free, it takes the waiting process that ranks highest in its own priority list.
- \(t = 0\): \(M_1\) takes \(P_1\) (runs 0 to 20) and \(M_2\) takes \(P_2\) (runs 0 to 16).
- \(t = 16\): \(M_2\) is free; \(P_3\) and \(P_4\) are waiting, and \(M_2\) prefers \(P_3\) (runs 16 to 41).
- \(t = 20\): \(M_1\) is free and only \(P_4\) is left (runs 20 to 30).
All processes arrive at time 0, so each waiting time equals its start time: \(0 + 0 + 16 + 20 = 36\), and the average is \(36 / 4 = 9.00\) ms.
Answer: A