Question:

Consider the following table of arrival and burst time in ms for three processes P0, P1, and P2.
 

The preemptive shortest job first scheduling algorithm is used. Scheduling is carried out only at arrival or completion of processes. What is the average waiting time for the three processes?

Show Hint

The preemptive SJF scheduling algorithm selects the process with the shortest burst time. Calculate the waiting time by subtracting the arrival time from the start time for each process.
Updated On: May 4, 2025
  • 7.33 ms
  • 5 ms
  • 4.33
  • 6.33
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

The preemptive shortest job first (SJF) scheduling algorithm works by selecting the process with the shortest burst time from the ready queue. Let's calculate the average waiting time:
1. At time 0, process P0 arrives with a burst time of 9 ms.
2. At time 1, process P1 arrives with a burst time of 4 ms, so it preempts P0.
3. At time 2, process P2 arrives with a burst time of 9 ms, but since P1 has the shortest burst time, P1 continues executing.
4. P1 finishes at time 5, and process P0, which has the next shortest burst time (9 ms), resumes.
5. P0 executes from time 5 to 9 and completes.
6. P2 starts executing at time 9 and finishes at time 18.
Now, calculate the waiting time for each process:
- Waiting time for P0: It started at time 5 and finished at time 9. So, waiting time = (start time - arrival time) = 5 - 0 = 5 ms.
- Waiting time for P1: It started at time 1 and finished at time 5. So, waiting time = (start time - arrival time) = 1 - 1 = 0 ms.
- Waiting time for P2: It started at time 9 and finished at time 18. So, waiting time = (start time - arrival time) = 9 - 2 = 7 ms.
The average waiting time is calculated as: \[ \text{Average Waiting Time} = \frac{5 + 0 + 7}{3} = 5 \, \text{ms} \]
Therefore, the correct answer is 2. 5 ms.
Was this answer helpful?
0
0