FCFS Scheduling
FCFS is the simplest scheduler: whoever arrives first runs first. It is easy to implement and easy to regret when one long job blocks everyone behind it.
In plain English
FCFS is a queue at a shop: first come, first served, even if a quick customer is stuck behind a big order.
By the end you will be able to
- Trace FCFS with arrival times and a Gantt chart.
- Compute completion, turnaround, and waiting times.
- Explain the convoy effect.
- Know when FCFS is acceptable and when it is not.
The algorithm
Sort the processes by arrival time. Keep a clock at zero. For each process in order, if the clock is earlier than its arrival, advance the clock to the arrival. Run the process for its full burst. Record the completion time. Because FCFS is non-preemptive, a running process is never interrupted.
sort_by_arrival(processes);
time = 0;
for each p in processes:
if time < p.arrival: time = p.arrival;
start = time;
time = time + p.burst;
p.completion = time;Worked example
Use P1 arrival 0 burst 5, P2 arrival 1 burst 3, P3 arrival 2 burst 1. P1 runs 0–5. P2 arrives at 1 but waits until 5, then runs 5–8. P3 arrives at 2 but waits until 8, then runs 8–9. Completion: 5, 8, 9. Turnaround: 5, 7, 7. Waiting: 0, 4, 6. Average waiting = 3.33.
| P1 | P2 | P3 |
0 5 8 9
P1: completion 5, turnaround 5, waiting 0
P2: completion 8, turnaround 7, waiting 4
P3: completion 9, turnaround 7, waiting 6The convoy effect
Suppose P1 has burst 20 and P2 and P3 have burst 1. P2 and P3 wait nearly 20 units behind P1. One long CPU-bound job can delay every short job behind it. This is the convoy effect. FCFS is fine for batch workloads where jobs are similar, but poor for interactive systems with mixed job lengths.
Watch it happen
Step through the worked example. Play it, pause it, or move one step at a time.
step-by-step
Step 1 of 3
t = 0 → 5 · P1
At t=0, P1 is first in arrival order, so it runs until t=5.
Key takeaways
- FCFS runs processes in arrival order.
- It is non-preemptive.
- The convoy effect lets one long job delay short jobs.
- FCFS is simple but not good at minimizing average waiting time.
- Always account for idle time when the CPU waits for the next arrival.
Common pitfalls
- Starting a process before its arrival time.
- Forgetting idle gaps in the Gantt chart.
- Assuming FCFS is fair to short jobs.
Kernel notes
- Trace FCFS with a clock and a sorted process list.
- Explain the convoy effect with a concrete example.
- Compute average waiting time from the completion times.
Quick check
1. What is the main weakness of FCFS?
2. P1 arrives at 0 with burst 4, P2 arrives at 2 with burst 2. When does P2 complete under FCFS?