FCFS Scheduling — Step-by-Step With Animated Numericals
Press Next → or use ← → arrow keys
The Story That Explains FCFS
How FCFS Works — The Algorithm
The Metrics — What We Compute
| Metric | Formula | Meaning |
|---|---|---|
| Completion Time (CT) | start + burst | The instant the process finishes |
| Turnaround Time (TAT) | CT − AT | Total time from arrival to completion |
| Waiting Time (WT) | TAT − BT | Time spent waiting in the ready queue |
| Response Time (RT) | start − AT | Time until the first CPU execution |
Because FCFS is non-preemptive, a process runs to completion the moment it first starts — there is no gap between "first run" and "kept running." So Response Time equals Waiting Time. Also useful: CPU Utilisation = busy ÷ total, and Throughput = processes ÷ total time.
Basic FCFS — All Arrive at t = 0
| Process | AT | BT | Start | CT | TAT | WT |
|---|---|---|---|---|---|---|
| P1 | 0 | 10 | 0 | 10 | 10 | 0 |
| P2 | 0 | 5 | 10 | 15 | 15 | 10 |
| P3 | 0 | 8 | 15 | 23 | 23 | 15 |
| Averages → | 16.00 | 8.33 | ||||
With all three arriving at t=0, they run in order P1 → P2 → P3. Read completion times straight off the
chart (10, 15, 23), then TAT = CT − AT and WT = TAT − BT.
Avg TAT = 16 ms, Avg WT = 8.33 ms, CPU utilisation 100%.
Different Arrival Times
| Process | AT | BT | Start | CT | TAT | WT |
|---|---|---|---|---|---|---|
| P1 | 0 | 6 | 0 | 6 | 6 | 0 |
| P2 | 2 | 4 | 6 | 10 | 8 | 4 |
| P3 | 4 | 2 | 10 | 12 | 8 | 6 |
| P4 | 6 | 3 | 12 | 15 | 9 | 6 |
| Averages → | 7.75 | 4.00 | ||||
P1 arrives first and runs 0→6; by then P2, P3, P4 have all queued, so they run in arrival order.
Note TAT differs from CT now, because arrival times aren't zero: TAT = CT − AT.
Avg TAT = 7.75 ms, Avg WT = 4.00 ms.
The Convoy Effect — Everyone Waits for P1
| Process | AT | BT | Start | CT | TAT | WT |
|---|---|---|---|---|---|---|
| P1 CPU-bound | 0 | 100 | 0 | 100 | 100 | 0 |
| P2 | 1 | 1 | 100 | 101 | 100 | 99 |
| P3 | 2 | 1 | 101 | 102 | 100 | 99 |
| P4 | 3 | 1 | 102 | 103 | 100 | 99 |
| Avg WT → | 74.25 | |||||
One long CPU-bound process arrived just before three tiny ones — and they all piled up behind it, like cars stuck behind a slow truck. Average waiting time explodes to 74.25 ms. This is the convoy effect, FCFS's fatal flaw.
Advantages & Disadvantages
With CPU Idle Time
| Process | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 3 | 3 | 3 | 0 |
| P2 | 5 | 4 | 9 | 4 | 0 |
| P3 | 10 | 2 | 12 | 2 | 0 |
| Averages → | 3.00 | 0.00 | |||
Each process arrives after the previous one finishes, so nobody ever waits — Avg WT = 0. But the CPU sits idle for 3 ms total (t=3–5 and t=9–10). Busy 9 of 12 ms → CPU utilisation = 75%. When the queue is empty, advance the clock to the next arrival.
Python Implementation
def fcfs(procs): # Sort by arrival to enforce FIFO order procs = sorted(procs, key=lambda p: p.arrival) clock = 0 for p in procs: clock = max(clock, p.arrival) # idle? jump ahead p.start = clock p.completion = clock + p.burst clock = p.completion return procs # TAT = CT - AT · WT = TAT - BT · RT = start - AT
Run it on Numerical 2's workload and it prints Avg TAT = 7.75, Avg WT = 4.00 —
identical to what we computed by hand. The whole algorithm is just: sort by arrival, walk the clock
forward, and jump ahead whenever the CPU would otherwise sit idle.
When Is FCFS a Good Choice?
Seven Rules for Solving FCFS
First Come, First Served — Mastered
Draw the Gantt chart in arrival order, read off completion times, then compute turnaround and waiting times. You've seen all four cases: simultaneous arrivals, staggered arrivals, the convoy effect, and CPU idle time.
The natural sequel is SJF (Shortest Job First), which fixes the convoy effect by running short jobs first, then Round Robin and Priority scheduling. Compare each one's average waiting time against this FCFS baseline.
🎫 End of tutorial · Press ← to review, or click Restart