Scheduling Processes with Non-Preemptive Priority Scheduling
This problem involves calculating the average waiting time for four processes ($P_1, P_2, P_3, P_4$) scheduled on two processors ($M_1, M_2$) using a non-preemptive priority scheduling algorithm. All processes arrive at the same time (time 0).
Understanding the Setup
- Processors: $M_1$, $M_2$
- Processes & CPU Bursts:
- $P_1$: 20 ms
- $P_2$: 16 ms
- $P_3$: 25 ms
- $P_4$: 10 ms
- Arrival Time: All processes arrive at time 0.
- Scheduling Algorithm: Non-preemptive Priority Scheduling.
- Processor $M_1$ Priority: $P_1 > P_3 > P_2 > P_4$ (Higher number means higher priority).
- Processor $M_2$ Priority: $P_2 > P_3 > P_4 > P_1$ (Higher number means higher priority).
- Scheduling Rule: A process runs if the processor is free and no higher priority process is waiting for that specific processor.
- Goal: Calculate the average waiting time.
Scheduling Simulation
We simulate the process execution step-by-step:
Initial Scheduling (Time = 0)
- Both processors $M_1$ and $M_2$ are free. All processes ($P_1, P_2, P_3, P_4$) are waiting.
- Processor $M_1$: Follows priority $P_1 > P_3 > P_2 > P_4$. The highest priority process available is $P_1$. Processor $M_1$ starts executing $P_1$.
- $P_1$ runs from time 0 ms to 20 ms (Burst time = 20 ms).
- Processor $M_2$: Follows priority $P_2 > P_3 > P_4 > P_1$. The highest priority process available is $P_2$. Processor $M_2$ starts executing $P_2$.
- $P_2$ runs from time 0 ms to 16 ms (Burst time = 16 ms).
Scheduling After $P_2$ Completes (Time = 16 ms)
- Processor $M_2$ becomes free at 16 ms.
- Processes remaining: $P_3$ (Burst=25), $P_4$ (Burst=10).
- Processor $M_1$ is still busy running $P_1$.
- Processor $M_2$: Priority is $P_2 > P_3 > P_4 > P_1$. Among the waiting processes ($P_3, P_4$), $P_3$ has the higher priority ($P_3 > P_4$). Processor $M_2$ starts executing $P_3$.
- $P_3$ runs from time 16 ms to $16 + 25 = 41$ ms.
Scheduling After $P_1$ Completes (Time = 20 ms)
- Processor $M_1$ becomes free at 20 ms.
- Process remaining: $P_4$ (Burst=10).
- Processor $M_2$ is busy running $P_3$.
- Processor $M_1$: Priority is $P_1 > P_3 > P_2 > P_4$. The only waiting process is $P_4$. Processor $M_1$ starts executing $P_4$.
- $P_4$ runs from time 20 ms to $20 + 10 = 30$ ms.
Process Completion Summary
- $P_1$ completed at 20 ms.
- $P_2$ completed at 16 ms.
- $P_4$ completed at 30 ms.
- $P_3$ completed at 41 ms.
Calculating Waiting Times
The waiting time for a process is the time elapsed from its arrival until it starts execution.
Waiting Time = Start Execution Time - Arrival Time
Since all processes arrive at time 0, the waiting time is simply the start time of execution.
- Waiting Time for $P_1$ ($W_{P1}$): Started at 0 ms. $W_{P1} = 0$ ms.
- Waiting Time for $P_2$ ($W_{P2}$): Started at 0 ms. $W_{P2} = 0$ ms.
- Waiting Time for $P_3$ ($W_{P3}$): Started at 16 ms. $W_{P3} = 16$ ms.
- Waiting Time for $P_4$ ($W_{P4}$): Started at 20 ms. $W_{P4} = 20$ ms.
Average Waiting Time Calculation
The average waiting time is the sum of all waiting times divided by the number of processes.
Average Waiting Time = $\frac{W_{P1} + W_{P2} + W_{P3} + W_{P4}}{4}$
Average Waiting Time = $\frac{0 \text{ ms} + 0 \text{ ms} + 16 \text{ ms} + 20 \text{ ms}}{4}$
Average Waiting Time = $\frac{36 \text{ ms}}{4}$
Average Waiting Time = $9$ ms
Therefore, the average waiting time of the processes is 9 milliseconds.