Consider the following four processes with the arrival time and length of CPU…

2017

Consider the following four processes with the arrival time and length of CPU burst given in milliseconds :

\(\begin{array}{ccc} \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time} \\ P_1 & 0 & 8 \\ P_2 & 1 & 4 \\ P_3 & 2 & 9 \\ P_4 & 3 & 5 \end{array}\)

The average waiting time for preemptive SJF scheduling algorithm is ____________

  1. A.

    6.5 ms

  2. B.

    7.5 ms

  3. C.

    6.75 ms

  4. D.

    7.75 ms

Attempted by 110 students.

Show answer & explanation

Correct answer: A

Answer: Average waiting time = 6.5 ms

Schedule (preemptive SJF / SRTF) timeline and completions:

  • t = 0 to 1: P1 runs (remaining P1 = 7)

  • t = 1 to 5: P2 runs and finishes at t = 5 (arrival 1, burst 4)

  • t = 5 to 10: P4 runs and finishes at t = 10 (arrival 3, burst 5)

  • t = 10 to 17: P1 resumes and finishes at t = 17 (arrival 0, total burst 8)

  • t = 17 to 26: P3 runs and finishes at t = 26 (arrival 2, burst 9)

Compute waiting times for each process:

  • P1: completion 17 − arrival 0 − burst 8 = 9 ms

  • P2: completion 5 − arrival 1 − burst 4 = 0 ms

  • P3: completion 26 − arrival 2 − burst 9 = 15 ms

  • P4: completion 10 − arrival 3 − burst 5 = 2 ms

Average waiting time = (9 + 0 + 15 + 2) / 4 = 26 / 4 = 6.5 ms.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor