ITPEC FE Morning April 2023 Question 18

Topic: Software

In preemptive Shortest Remaining Time First (SRTF) scheduling, on arrival or completion of any process, the scheduler schedules processes from the list of available processes and running processes that have the least remaining CPU-burst time. The four processes, namely, P1, P2, P3, and P4, their corresponding CPU-burst time and arrival time are shown in the table below. Which of the following is the average waiting time in milliseconds for the processes to be executed in preemptive SRTF scheduling?

ProcessArrival time inmillisecondCPU-burst time inmillisecond
P108
P223
P337
P454

Explanation

4.75 ms — build the SRTF timeline, then average the time each process spends ready but not running.

Timeline, with a decision at every arrival and completion:

  • •0–2: P1 runs alone; 6 ms remain
  • •At 2: P2 arrives needing 3, less than P1's 6, so it preempts P1
  • •At 3: P3 arrives needing 7; P2 has 2 left and keeps running
  • •At 5: P2 finishes and P4 arrives; remaining times are P1 6, P3 7, P4 4, so P4 runs 5–9
  • •9–15: P1 runs its last 6 ms, then 15–22: P3

Waiting time is completion minus arrival minus burst:

ProcessCompletionWaiting
P11515 − 0 − 8 = 7
P255 − 2 − 3 = 0
P32222 − 3 − 7 = 12
P499 − 5 − 4 = 0

Average: (7 + 0 + 12 + 0) ÷ 4 = 4.75 ms

Answer (b)

Why not others:

  • •(a) 3.0 — counts only the wait before each process first runs, (0 + 0 + 12 + 0) ÷ 4, ignoring the 7 ms P1 waits after being preempted
  • •(c) 5.5 — the average CPU-burst time, (8 + 3 + 7 + 4) ÷ 4, not a waiting time
  • •(d) 10.25 — the average turnaround time, (15 + 3 + 19 + 4) ÷ 4, which includes the running time

Key rule: Waiting time is turnaround minus burst, and turnaround is completion minus arrival; with preemption a process can wait in several pieces, and all of them count.

Software · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.