Sub topic 12
First-Come First-Served and the Convoy Effect
Prerequisites and the Basic Rule
This chapter assumes that you know process arrival time, CPU burst time, and Gantt charts. An arrival time is when a process enters the ready queue. A CPU burst is the amount of CPU time the process needs before it blocks or finishes.
First-Come First-Served (FCFS) scheduling gives the CPU to the process that enters the ready queue first. It uses a first-in, first-out queue. FCFS is usually non-preemptive, which means the operating system does not take the CPU away until the running process finishes its CPU burst.
If the ready queue is empty, the CPU stays idle until a process arrives. If several processes arrive at the same time, the question must specify their tie-breaking order. Otherwise, use the stated or assumed order.
Worked Example
Consider these processes:
| Process | Arrival time | CPU burst |
|---|---|---|
| P1 | 0 | 8 |
| P2 | 1 | 3 |
| P3 | 2 | 2 |
P1 starts immediately and runs until time 8. P2 and P3 wait in arrival order. The Gantt chart is:
0–8 P1 | 8–11 P2 | 11–13 P3
For each process:
- Completion time is when its CPU burst ends.
- Turnaround time = completion time − arrival time.
- Waiting time = turnaround time − CPU burst.
- Response time = first CPU start time − arrival time.
| Process | Completion | Turnaround | Waiting | Response |
|---|---|---|---|---|
| P1 | 8 | 8 | 0 | 0 |
| P2 | 11 | 10 | 7 | 7 |
| P3 | 13 | 11 | 9 | 9 |
The average waiting time is (0 + 7 + 9) / 3 = 16 / 3 time units. In non-preemptive FCFS, a process's response time equals its waiting time because it receives the CPU only once.
The Convoy Effect
The convoy effect occurs when a long CPU-bound process runs before many short or I/O-bound processes. The short processes form a convoy behind it. While they wait, their I/O devices may remain unused. After they run briefly and block for I/O, the long process may run again, producing another delay.
FCFS is simple, has low scheduling overhead, and does not starve a process that remains in the queue. However, its average waiting and response times can be poor. The order of arrivals strongly affects performance.
Exercise
Processes P1, P2, and P3 arrive at time 0 with CPU bursts 4, 1, and 2, respectively. FCFS uses the order P1, P2, P3. What are the waiting times and average waiting time?
Show answer
The waiting times are P1 = 0, P2 = 4, and P3 = 5. The average waiting time is (0 + 4 + 5) / 3 = 3 time units.