Numerical: compute average waiting and turnaround times under FCFS and SJF.
HardConceptOS Numericals
Answer
Problem: P1, P2, P3 and P4 arrive at times 0, 2, 4 and 5 with CPU bursts of 7, 4, 1 and 4. Find the average waiting and turnaround times under FCFS and non-preemptive SJF. Answer: FCFS 4.75 and 8.75; SJF 4 and 8.
- Draw the Gantt chart, then use TAT = CT − AT (completion minus arrival) and WT = TAT − BT (turnaround minus burst).
- In non-preemptive SJF, choose only among processes that have already arrived when the CPU becomes free; break ties by arrival time.
- Check: the CPU never idles here, so the last completion time equals the total burst, 7 + 4 + 1 + 4 = 16.
Example (worked solution):
FCFS: P1 0-7, P2 7-11, P3 11-12, P4 12-16
SJF: P1 0-7, P3 7-8, P2 8-12, P4 12-16
At time 7, SJF picks P3 (burst 1); P2 then beats P4 (both 4) because it arrived first.
| Process | FCFS CT, TAT, WT | SJF CT, TAT, WT |
|---|---|---|
| P1 | 7, 7, 0 | 7, 7, 0 |
| P2 | 11, 9, 5 | 12, 10, 6 |
| P3 | 12, 8, 7 | 8, 4, 3 |
| P4 | 16, 11, 7 | 16, 11, 7 |
Averages: FCFS TAT 35 / 4 = 8.75, WT 19 / 4 = 4.75; SJF TAT 32 / 4 = 8, WT 16 / 4 = 4.