FCFS scheduling algorithm
FCFS scheduling algorithm
The First Come First Serve (FCFS) CPU scheduling algorithm is the simplest type of
scheduling algorithm. In FCFS, the process that arrives first is executed first, without considering
the priority or the burst time (execution time) of the process. It's similar to standing in a queue at
a bank where the first person to arrive is the first to be served.
• Non-preemptive: Once the CPU starts executing a process, it will finish it before moving
to the next process.
• Queue-based: Processes are handled in the order they arrive.
Steps of FCFS:
Example of FCFS:
Step-by-step Execution:
1. P1 arrives at time 0 and starts executing since it is the first to arrive. It finishes after 5ms.
2. P2 arrives at time 1, but it must wait until P1 finishes. P2 starts at time 5 and runs for
3ms, finishing at time 8.
3. P3 arrives at time 2, but it must wait for both P1 and P2 to finish. P3 starts at time 8 and
runs for 8ms, finishing at time 16.
Gantt Chart:
| P1 | P2 | P3 |
0 5 8 16
Important Metrics:
• Turnaround Time = Completion Time - Arrival Time
o P1: 5 - 0 = 5 ms
o P2: 8 - 1 = 7 ms
o P3: 16 - 2 = 14 ms
• Waiting Time = Turnaround Time - Burst Time
o P1: 5 - 5 = 0 ms
o P2: 7 - 3 = 4 ms
o P3: 14 - 8 = 6 ms
Pros of FCFS:
Cons of FCFS:
• Non-preemptive: If a process with a long burst time arrives first, other processes will
have to wait (leading to poor performance for short tasks).
• Convoy Effect: Shorter processes may get delayed by longer processes.
In this example, P3 had to wait a long time because P1 and P2 arrived earlier. FCFS is not ideal
for time-critical processes but works fine when all processes have similar burst times.