2079 6

CSC264 ยท 2079 ยท 5 marks

For the following dataset, compute average waiting time for SRTN and SJF. | Process | Arrival Time | Burst Time | |---------|--------------|------------| | P0 | 0 | 7 | | P1 | 2 | 4 | | P2 | 4 | 1 | | P3 | 5 | 4 |

For the following dataset, compute average waiting time for SRTN and SJF.

ProcessArrival TimeBurst Time
P007
P124
P241
P354

[5]

Operating SystemsChapter 2: Process ManagementProcess SchedulingNumerical: SRTN and SJF schedulingVideo solution

SRTN and SJF Scheduling - Average Waiting Time

Given

ProcessArrival TimeBurst Time
P007
P124
P241
P354

All required data present.


Solution

Part 1: SRTN (Shortest Remaining Time Next) - Preemptive

At each new arrival, compare remaining times and run the smallest.

Execution Trace

  • t=0: Only P0. Run P0.
  • t=2: P1 arrives (4). P0 remaining = 5. Since 4 < 5, run P1. (P0 rem = 5)
  • t=4: P2 arrives (1). P1 remaining = 2. Since 1 < 2, run P2. (P0=5, P1=2)
  • t=5: P2 finishes. P3 arrives (4). Ready: P1=2, P3=4, P0=5. Run P1.
  • t=7: P1 finishes. Ready: P3=4, P0=5. Run P3.
  • t=11: P3 finishes. Run P0 (5 remaining).
  • t=16: P0 finishes.

Note: at $t=4$ the remaining time for P1 is $4 - 2 = \mathbf{2}$ units, since P1 ran from $t=2$ to $t=4$.

Gantt Chart

| P0 | P1 | P2 | P1 | P3 | P0  |
0    2    4    5    7   11   16

Waiting Time (WT = Completion - Arrival - Burst)

ProcessCompletionArrivalBurstWaiting Time
P0160716 - 0 - 7 = 9
P17247 - 2 - 4 = 1
P25415 - 4 - 1 = 0
P3115411 - 5 - 4 = 2

$$\text{Average WT (SRTN)} = \frac{9 + 1 + 0 + 2}{4} = \frac{12}{4} = \boxed{3.0 \text{ ms}}$$


Part 2: SJF (Shortest Job First) - Non-Preemptive

  • t=0: Only P0 arrived. Run P0 to completion โ†’ finishes at 7.
  • t=7: P1(4), P2(1), P3(4) all arrived. Shortest = P2. Run P2 โ†’ finishes at 8.
  • t=8: P1(4), P3(4). Tie broken by arrival โ†’ P1. Finishes at 12.
  • t=12: P3 runs โ†’ finishes at 16.

Gantt Chart

| P0      | P2 | P1     | P3     |
0         7    8       12      16

Waiting Time

ProcessCompletionArrivalBurstWaiting Time
P07070
P112246
P28413
P316547

$$\text{Average WT (SJF)} = \frac{0 + 6 + 3 + 7}{4} = \frac{16}{4} = \boxed{4.0 \text{ ms}}$$


Summary

AlgorithmAverage Waiting Time
SRTN (Preemptive)3.0 ms
SJF (Non-Preemptive)4.0 ms

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.