FCFS - First Come First Serve CPU Scheduling
Last Updated :
12 Jul, 2025
First Come, First Serve (FCFS) is one of the simplest types of CPU scheduling algorithms. It is exactly what it sounds like: processes are attended to in the order in which they arrive in the ready queue, much like customers lining up at a grocery store.
FCFS Scheduling is a non-preemptive algorithm, meaning once a process starts running, it cannot be stopped until it voluntarily relinquishes the CPU, typically when it terminates or performs I/O. This method schedules processes in the order they arrive, without considering priority or other factors.
How Does FCFS Work?
The mechanics of FCFS are straightforward:
- Arrival: Processes enter the system and are placed in a queue in the order they arrive.
- Execution: The CPU takes the first process from the front of the queue, executes it until it is complete, and then removes it from the queue.
- Repeat: The CPU takes the next process in the queue and repeats the execution process.
This continues until there are no more processes left in the queue.
Example of FCFS CPU Scheduling:
To understand the First Come, First Served (FCFS) scheduling algorithm effectively, we'll use two examples -
- one where all processes arrive at the same time,
- another where processes arrive at different times.
We'll create Gantt charts for both scenarios and calculate the turnaround time and waiting time for each process.
Scenario 1: Processes with Same Arrival Time
Consider the following table of arrival time and burst time for three processes P1, P2 and P3
Process | Arrival Time | Burst Time |
---|
p1 | 0 | 5 |
---|
p2 | 0 | 3 |
---|
p3 | 0 | 8 |
---|
Step-by-Step Execution:
- P1 will start first and run for 5 units of time (from 0 to 5).
- P2 will start next and run for 3 units of time (from 5 to 8).
- P3 will run last, executing for 8 units (from 8 to 16).
Gant Chart:
Now, let's calculate average waiting time and turn around time:
Turnaround Time = Completion Time - Arrival Time
Waiting Time = Turnaround Time - Burst Time
AT : Arrival Time
BT : Burst Time or CPU Time
TAT : Turn Around Time
WT : Waiting Time
Processes | AT | BT | CT | TAT | WT |
---|
P1 | 0 | 5 | 5 | 5-0 = 5 | 5-5 = 0 |
P2 | 0 | 3 | 8 | 8-0 = 8 | 8-3 = 5 |
P3 | 0 | 8 | 16 | 16-0 = 16 | 16-8 = 8 |
- Average Turn around time = 9.67
- Average waiting time = 4.33
Scenario 2: Processes with Different Arrival Times
Consider the following table of arrival time and burst time for three processes P1, P2 and P3
Process | Burst Time (BT) | Arrival Time (AT) |
---|
P1 | 5 ms | 2 ms |
P2 | 3 ms | 0 ms |
P3 | 4 ms | 4 ms |
Step-by-Step Execution:
- P2 arrives at time 0 and runs for 3 units, so its completion time is:
Completion Time of P2=0+3=3 - P1 arrives at time 2 but has to wait for P2 to finish. P1 starts at time 3 and runs for 5 units. Its completion time is:
Completion Time of P1=3+5=8 - P3 arrives at time 4 but has to wait for P1 to finish. P3 starts at time 8 and runs for 4 units. Its completion time is:
Completion Time of P3=8+4=12
Gantt Chart:
Now, lets calculate average waiting time and turn around time:
Process | Completion Time (CT) | Turnaround Time (TAT = CT - AT) | Waiting Time (WT = TAT - BT) |
---|
P2 | 3 ms | 3 ms | 0 ms |
P1 | 8 ms | 6 ms | 1 ms |
P3 | 12 ms | 8 ms | 4 ms |
- Average Turnaround time = 5.67
- Average waiting time = 1.67
Code Implementation
Advantages of FCFS
- The simplest and basic form of CPU Scheduling algorithm
- Every process gets a chance to execute in the order of its arrival. This ensures that no process is arbitrarily prioritized over another.
- Easy to implement, it doesn't require complex data structures.
- Since processes are executed in the order they arrive, there’s no risk of starvation
- It is well suited for batch systems where the longer time periods for each process are often acceptable.
Disadvantages of FCFS
- As it is a Non-preemptive CPU Scheduling Algorithm, FCFS can result in long waiting times, especially if a long process arrives before a shorter one. This is known as the convoy effect, where shorter processes are forced to wait behind longer processes, leading to inefficient execution.
- The average waiting time in the FCFS is much higher than in the others
- Since FCFS processes tasks in the order they arrive, short jobs may have to wait a long time if they arrive after longer tasks, which leads to poor performance in systems with a mix of long and short tasks.
- Processes that are at the end of the queue, have to wait longer to finish.
- It is not suitable for time-sharing operating systems where each process should get the same amount of CPU time.
First Come First Serve (FCFS) CPU Scheduling Algorithm with Example
Similar Reads
Priority CPU Scheduling with different arrival time - Set 2 Prerequisite -Program for Priority Scheduling - Set 1Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems. Each process is assigned first arrival time (less arrival time process first) if two processes have same arrival time, then compar
11 min read
Preemptive Priority CPU Scheduling Algorithm Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method of CPU scheduling algorithm that works based on the priority of a process. In this algorithm, the scheduler schedules the tasks to work as per the priority, which means that a higher priority process should be executed first. In ca
15+ min read
Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive) The shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJN, also known as Shortest Job Next (SJN), can be preemptive or non-preemptive. Â Characteristics of SJF Scheduling: Shortest Job first has th
13 min read
Longest Remaining Time First (LRTF) CPU Scheduling Program We have given some processes with arrival time and Burst Time and we have to find the completion time (CT), Turn Around Time(TAT), Average Turn Around Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given processes. Prerequisite: CPU Scheduling | Longest Remaining Time First (LR
15+ min read
Longest Remaining Time First (LRTF) CPU Scheduling Program We have given some processes with arrival time and Burst Time and we have to find the completion time (CT), Turn Around Time(TAT), Average Turn Around Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given processes. Prerequisite: CPU Scheduling | Longest Remaining Time First (LR
15+ min read
Longest Remaining Time First (LRTF) CPU Scheduling Program We have given some processes with arrival time and Burst Time and we have to find the completion time (CT), Turn Around Time(TAT), Average Turn Around Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given processes. Prerequisite: CPU Scheduling | Longest Remaining Time First (LR
15+ min read