Consider the following processes, all arriving at time 0, with their…

2023

Consider the following processes, all arriving at time 0, with their respective burst times:

image.png

Using Non-Preemptive Shortest Job First (SJF) scheduling, calculate the average waiting time.

  1. A.

    7.0 ms

  2. B.

    6.25 ms

  3. C.

    5.0 ms

  4. D.

    6.0 ms

  5. E.

    5.5 ms

Attempted by 21 students.

Show answer & explanation

Correct answer: A

Concept

In Non-Preemptive Shortest Job First (SJF) scheduling, whenever the CPU is free it picks the ready process with the smallest CPU burst and runs it to completion without interruption. A process's waiting time is the total time it spends in the ready queue before it starts executing; for processes that all arrive at time 0, that equals the sum of the burst times of every process scheduled ahead of it. Average waiting time (AWT) is the mean of the individual waiting times.

Application

All four processes arrive at time 0, so SJF simply orders them by increasing burst time and runs them one after another:

Order of execution

Process

Burst (ms)

Starts at

Waiting time (ms)

1st

burst 3

3

0

0

2nd

burst 6

6

3

3

3rd

burst 7

7

9

9

4th

burst 8

8

16

16

Building up the waiting time step by step:

  1. The 3 ms process runs first: it starts immediately, so its waiting time is 0.

  2. The 6 ms process runs next: it waited while the 3 ms process ran, so its waiting time is 3.

  3. The 7 ms process runs next: it waited for 3 + 6, so its waiting time is 9.

  4. The 8 ms process runs last: it waited for 3 + 6 + 7, so its waiting time is 16.

AWT = (0 + 3 + 9 + 16) / 4 = 28 / 4 = 7.0 ms.

Cross-check

Independent check using turnaround time: the completion times are 3, 9, 16, 24, so the turnaround times are 3, 9, 16, 24. Subtracting each burst (3, 6, 7, 8) gives waiting times 0, 3, 9, 16, whose mean is again 7.0 ms. SJF is also optimal here: it gives the smallest possible average waiting time for this set, which any other order (for example first-come-first-served) would only increase.

Explore the full course: Niacl Ao It Specialist