Consider a single processor system with four processes A, B, C, and D,…

2024

Consider a single processor system with four processes A, B, C, and D, represented as given below, where for each process the first value is its arrival time, and the second value is its CPU burst time.

A (0, 10), B (2, 6), C (4, 3), and D (6, 7).

Which one of the following options gives the average waiting times when preemptive Shortest Remaining Time First (SRTF) and Non-Preemptive Shortest Job First (NP-SJF) CPU scheduling algorithms are applied to the processes?

  1. A.

    SRTF = 6, NP-SJF = 7

  2. B.

    SRTF = 6, NP-SJF = 7.5

  3. C.

    SRTF = 7, NP-SJF = 7.5

  4. D.

    SRTF = 7, NP-SJF = 8.5

Attempted by 154 students.

Show answer & explanation

Correct answer: B

SRTF (Preemptive Shortest Remaining Time First): simulate timeline and compute waiting times.

  • t=0–2: A runs (A remaining becomes 8 at t=2).

  • t=2–4: B runs (B remaining becomes 4 at t=4).

  • t=4–7: C (burst 3) runs and completes at t=7 (waiting time for C = completion − arrival − burst = 7−4−3 = 0).

  • t=7–11: B resumes and completes at t=11 (waiting for B = 11−2−6 = 3).

  • t=11–18: D runs and completes at t=18 (waiting for D = 18−6−7 = 5).

  • t=18–26: A resumes and completes at t=26 (waiting for A = 26−0−10 = 16).

Per-process waiting times (SRTF):

  • A = 16

  • B = 3

  • C = 0

  • D = 5

Average waiting time (SRTF) = (16 + 3 + 0 + 5) / 4 = 6.

NP-SJF (Non-preemptive Shortest Job First): simulate timeline and compute waiting times.

  • t=0–10: A runs to completion (A waiting = 0).

  • t=10–13: Among arrived jobs B, C, D, C has shortest burst (3) so C runs and completes at t=13 (waiting for C = 13−4−3 = 6).

  • t=13–19: Next shortest is B (6), so B runs and completes at t=19 (waiting for B = 19−2−6 = 11).

  • t=19–26: D runs and completes at t=26 (waiting for D = 26−6−7 = 13).

Per-process waiting times (NP-SJF):

  • A = 0

  • B = 11

  • C = 6

  • D = 13

Average waiting time (NP-SJF) = (0 + 11 + 6 + 13) / 4 = 7.5.

Conclusion: The correct averages are SRTF = 6 and NP-SJF = 7.5.

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

Explore the full course: Gate Guidance By Sanchit Sir