Let there be four processes P1, P2, P3, P4 whose CPU burst times are 6, 8, 7,…
2022
Let there be four processes P1, P2, P3, P4 whose CPU burst times are 6, 8, 7, 3 ms, respectively, and they arrive at time 0. Which of the following is the average waiting time and order of the process scheduling under the shortest-job-first scheduling?
- A.
Average Waiting time = 7.75 ms; Process order: P1, P4, P3, P2
- B.
Average Waiting time = 7 ms; Process order: P4, P1, P3, P2
- C.
Average Waiting time = 9.25 ms; Process order: P2, P4, P3, P1
- D.
Average Waiting time = 10.25 ms; Process order: P1, P2, P3, P4
Attempted by 159 students.
Show answer & explanation
Correct answer: B
In shortest-job-first (SJF) scheduling with non-preemptive execution, whenever every process is already available (arrives at time 0), the scheduler always picks the process with the smallest burst time next; because the order is decided just once at the start, the waiting time of each process equals the sum of the burst times of every process that runs before it, and the average waiting time is the mean of these four waiting times.
The given burst times are P1 = 6 ms, P2 = 8 ms, P3 = 7 ms, P4 = 3 ms; sorting them in ascending order of burst time gives the execution sequence P4 (3 ms) -> P1 (6 ms) -> P3 (7 ms) -> P2 (8 ms).
P4 runs first, so it waits 0 ms.
P1 runs second, so it waits for P4's entire burst time: 3 ms.
P3 runs third, so it waits for P4 and P1's combined burst time: 3 + 6 = 9 ms.
P2 runs last, so it waits for P4, P1 and P3's combined burst time: 3 + 6 + 7 = 16 ms.
The average waiting time is (0 + 3 + 9 + 16) / 4 = 28 / 4 = 7 ms, with the execution order P4, P1, P3, P2.
As an independent check, the sum of the four waiting times (28 ms) must equal the sum of each process's burst time multiplied by the number of processes still waiting behind it in the queue: (3 x 3) + (6 x 2) + (7 x 1) + (8 x 0) = 9 + 12 + 7 + 0 = 28 ms, which matches, confirming the average of 7 ms.