Numerical: compute waiting and turnaround times under SRTF and Round Robin.
HardConceptOS Numericals
Answer
Problem: P1, P2, P3 and P4 arrive at times 0, 2, 4 and 5 with bursts of 7, 4, 1 and 4. Find the average waiting and turnaround times under SRTF and Round Robin (quantum 2). Answer: SRTF 3 and 7; RR 5 and 9.
- SRTF (Shortest Remaining Time First, preemptive SJF): when a process arrives, preempt the running process if the newcomer's burst is shorter than its remaining time.
- RR: a process whose quantum expires joins the back of the queue, behind any process arriving at that same moment.
Example (worked solution):
SRTF: P1 0-2, P2 2-4, P3 4-5, P2 5-7, P4 7-11, P1 11-16
RR: P1 0-2, P2 2-4, P1 4-6, P3 6-7, P2 7-9, P4 9-11, P1 11-13, P4 13-15, P1 15-16
In SRTF, P2 (4) preempts P1 (5 left) at time 2, P3 (1) preempts P2 (2 left) at time 4, and P2 (2 left) then beats P4 (4).
| Process | SRTF CT, TAT, WT | RR CT, TAT, WT |
|---|---|---|
| P1 | 16, 16, 9 | 16, 16, 9 |
| P2 | 7, 5, 1 | 9, 7, 3 |
| P3 | 5, 1, 0 | 7, 3, 2 |
| P4 | 11, 6, 2 | 15, 10, 6 |
Averages: SRTF TAT 28 / 4 = 7, WT 12 / 4 = 3; RR TAT 36 / 4 = 9, WT 20 / 4 = 5. RR trades average waiting time for fairness.