Sub topic 12
First-Come First-Served and the Convoy Effect
This chapter assumes you know what the ready queue is, what a CPU burst is, and the definitions of waiting, turnaround and response time from the previous chapter. It also assumes the difference between preemptive and non-preemptive scheduling. You will see how FCFS works, how to compute its metrics by hand and in code, and why a single long process can slow everyone else down.
The Rule
First-Come First-Served (FCFS) gives the CPU to the process that arrived in the ready queue first. The ready queue is a plain FIFO queue. Three properties define the algorithm:
- It is non-preemptive. Once a process gets the CPU, it keeps it until it finishes or blocks for I/O. A timer interrupt does not take the CPU away.
- It needs almost no bookkeeping. Enqueue at the tail, dequeue from the head.
- It is fair in the narrow sense that order of arrival decides everything. No process starves, because every process ahead of you eventually finishes or blocks.
A process that blocks for I/O leaves the CPU. When its I/O completes, it re-enters the ready queue at the tail. It does not get its old place back.
Computing the Metrics
For a non-preemptive algorithm with a single CPU burst per process, the formulas simplify:
- Turnaround time = finish time − arrival time
- Waiting time = turnaround time − burst time = start time − arrival time
- Response time = first CPU time − arrival time
For FCFS without preemption, response time equals waiting time. The process starts once and never leaves, so the first time it gets the CPU is also the end of all its waiting.
Worked example with arrival times
| Process | Arrival | Burst |
|---|---|---|
| P1 | 0 | 4 |
| P2 | 1 | 3 |
| P3 | 2 | 1 |
| P4 | 3 | 2 |
The order is P1, P2, P3, P4, so the Gantt chart is:
| P1 | P2 | P3 | P4 |
0 4 7 8 10| Process | Start | Finish | Turnaround | Waiting |
|---|---|---|---|---|
| P1 | 0 | 4 | 4 | 0 |
| P2 | 4 | 7 | 6 | 3 |
| P3 | 7 | 8 | 6 | 5 |
| P4 | 8 | 10 | 7 | 5 |
Average waiting time is (0 + 3 + 5 + 5) / 4 = 3.25. Average turnaround time is (4 + 6 + 6 + 7) / 4 = 5.75.
Notice that P3 needs only 1 time unit but waits 5. That is the weakness of FCFS in small form.
A Simulation You Can Run
The function below sorts by arrival time. Python's sort is stable, so equal arrivals keep their input order. That matches the usual GATE tie-break, which is to pick the lower process number. It also handles idle gaps, where the CPU waits for the next arrival.
def fcfs(processes):
"""processes: list of (name, arrival, burst). Returns per-process rows."""
order = sorted(processes, key=lambda p: p[1]) # stable sort by arrival
t = 0
rows = []
for name, arrival, burst in order:
start = max(t, arrival) # CPU idles if nothing has arrived yet
finish = start + burst
rows.append({
"name": name,
"start": start,
"finish": finish,
"turnaround": finish - arrival,
"waiting": start - arrival,
})
t = finish
return rows
procs = [("P1", 0, 4), ("P2", 1, 3), ("P3", 2, 1), ("P4", 3, 2)]
rows = fcfs(procs)
for r in rows:
print(r["name"], r["start"], r["finish"], r["turnaround"], r["waiting"])
print("avg waiting =", sum(r["waiting"] for r in rows) / len(rows))
print("avg turnaround =", sum(r["turnaround"] for r in rows) / len(rows))The output matches the table: average waiting 3.25 and average turnaround 5.75.
The max(t, arrival) line is the part students most often forget on paper. If a process arrives at time 12 and the CPU became free at time 10, the CPU is idle from 10 to 12. The process starts at 12 and its waiting time is 0.
The Order Matters: Same Jobs, Different Average
FCFS average waiting time can vary a lot with arrival order. Take three processes that all arrive at time 0:
| Process | Burst |
|---|---|
| P1 | 24 |
| P2 | 3 |
| P3 | 3 |
If they are served in the order P1, P2, P3, the waiting times are 0, 24 and 27. The average is 51 / 3 = 17.
If they are served in the order P2, P3, P1, the waiting times are 0, 3 and 6. The average is 9 / 3 = 3.
The work done and the finish time of the whole batch (30) are identical. Only the average waiting time changes, from 17 to 3. FCFS has no control over this, because it never looks at burst length.
The Convoy Effect
The convoy effect is the slowdown that happens when many short processes queue behind one long process, like cars stuck behind a slow truck.
The effect is worse with a mix of CPU-bound and I/O-bound processes. A CPU-bound process uses long CPU bursts. An I/O-bound process uses short CPU bursts between I/O requests. Suppose one CPU-bound process and several I/O-bound processes run under FCFS:
- The CPU-bound process gets the CPU and holds it for a long burst.
- Meanwhile, the I/O-bound processes finish their I/O and join the ready queue. The I/O devices now sit idle.
- The CPU-bound process finally blocks or ends. The I/O-bound processes each run a short burst, issue another I/O request, and leave the CPU.
- The ready queue empties. The CPU may now sit idle while the I/O-bound processes use the devices, until the CPU-bound process returns.
The result is poor use of both the CPU and the I/O devices, and a lower throughput than a better ordering would give. The cause is the same in each step. FCFS cannot take the CPU away from a long job and cannot prefer a short one.
Properties to Remember
| Property | FCFS |
|---|---|
| Preemptive | No |
| Starvation | None, because every process eventually reaches the head |
| Average waiting time | Often large, and sensitive to arrival order |
| Optimal for average waiting time | No (SJF is, for known bursts) |
| Good for interactive systems | No, because response time can be very long |
| Implementation cost | Very low (a FIFO queue) |
Two connections to other algorithms are useful. Round Robin with a quantum larger than every burst behaves exactly like FCFS. Priority scheduling falls back to FCFS to break ties between processes of the same priority.
Common Mistakes in Problems
- Ordering by listing, not by arrival. The table may list processes in a different order from their arrival times. Sort by arrival first.
- Forgetting idle time. If the ready queue is empty, the CPU waits. The next start time is that process's arrival time.
- Using the wrong formula. Waiting = turnaround − burst only works when the process has a single burst and no I/O. If I/O bursts appear in the question, waiting time counts only the time spent in the ready queue.
- Breaking ties wrongly. When two processes arrive at the same moment, use the lower process ID unless the question states another rule.
- Mixing up response and waiting time. For FCFS they are equal, but for preemptive algorithms they are not.
Exercise
Four processes use FCFS on one CPU: P1 (arrival 0, burst 8), P2 (arrival 1, burst 4), P3 (arrival 2, burst 9), P4 (arrival 3, burst 5). Compute the average waiting time and the average turnaround time.
Show answer
The order is P1, P2, P3, P4. The Gantt chart is P1 0-8, P2 8-12, P3 12-21, P4 21-26. Waiting times (start − arrival) are 0, 7, 10 and 18, so the average is 35 / 4 = 8.75. Turnaround times (finish − arrival) are 8, 11, 19 and 23, so the average is 61 / 4 = 15.25.
Exercise
A system runs one CPU-bound process and ten I/O-bound processes under FCFS. Describe what happens to the CPU and the I/O devices when the CPU-bound process is dispatched, and name the effect.
Show answer
While the CPU-bound process holds the CPU, the I/O-bound processes finish their I/O and wait in the ready queue, so the I/O devices go idle. When the CPU-bound process releases the CPU, the I/O-bound processes run briefly and go back to I/O, so the CPU can become idle. Both resources are underused. This is the convoy effect.
Exercise
Processes P1 (arrival 0, burst 3) and P2 (arrival 10, burst 2) run under FCFS. What is the finish time of P2, and what is the CPU doing between times 3 and 10?
Show answer
P1 runs from 0 to 3. The CPU is idle from 3 to 10 because P2 has not arrived. P2 starts at 10 with a waiting time of 0 and finishes at 12.