Compare FCFS and SJF scheduling. What is the convoy effect?
MediumConceptCPU Scheduling
Answer
First-Come, First-Served (FCFS) runs processes in the order they arrive, like a queue at a ticket counter. Shortest Job First (SJF) always picks the ready process with the smallest CPU burst.
- FCFS is simple and never starves anyone, but it suffers from the convoy effect: short processes stuck behind one long process all wait, so the average waiting time becomes large.
- SJF gives the minimum possible average waiting time for a set of processes, because running short jobs first reduces how long all the others wait.
- SJF needs burst lengths in advance, which the OS cannot know, so it predicts the next burst from past ones by exponential averaging: τ(next) = α × t(last actual) + (1 − α) × τ(last prediction). Long jobs can also starve if short ones keep arriving.
Example: P1, P2 and P3 arrive at time 0 with bursts of 24, 3 and 3 ms.
| Order | Waiting times | Average |
|---|---|---|
| FCFS: P1, P2, P3 | 0, 24, 27 | 51 / 3 = 17 ms |
| SJF: P2, P3, P1 | 0, 3, 6 | 9 / 3 = 3 ms |
For prediction with α = 0.5, a previous prediction of 10 ms and an actual burst of 6 ms, the next prediction is 0.5 × 6 + 0.5 × 10 = 8 ms.