FCFS - First Come First Serve CPU Scheduling
Last Updated :
11 Mar, 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.
Similar Reads
C-LOOK Disk Scheduling Algorithm C-LOOK Disk Scheduling Algorithm is an enhanced version of both SCAN as well as LOOK disk scheduling algorithms. This algorithm also uses the idea of wrapping the tracks as a circular cylinder as the C-SCAN Algorithm but the seek time is better than the C-SCAN algorithm. We know that C-SCAN is used
13 min read
CPU Scheduling in Operating Systems using priority queue with gantt chart Prerequisite: CPU Scheduling in Operating SystemsDifferent Scheduling Algorithms: First Come First Serve CPU Scheduling: Simplest scheduling algorithm that schedules according to arrival times of processes. First come first serve scheduling algorithm states that the process that requests the CPU fir
15+ min read
FCFS Scheduling Full Form - First Come First Serve FCFS stands for First Come First Serve. In the FCFS scheduling algorithm, the job that arrived first in the ready queue is allocated to the CPU and then the job that came second, and so on. We can say that the ready queue acts as a FIFO (First In First Out) queue thus the arriving jobs/processes are
3 min read
Program for FCFS CPU Scheduling | Set 1 First come - First served (FCFS), is the simplest scheduling algorithm. FIFO simply queues processes according to the order they arrive in the ready queue. In this algorithm, the process that comes first will be executed first and next process starts only after the previous gets fully executed. Term
15+ min read
Fair-share CPU scheduling Fair-share scheduling is a scheduling algorithm that was first designed by Judy Kay and Piers Lauder at Sydney University in the 1980s. It is a scheduling algorithm for computer operating systems that dynamically distributes the time quanta "equally" to its users. Time quantum is the processor time
2 min read
Difference between Multi Level Queue Scheduling (MLQ) and First Come First Served (FCFS) Processes are scheduled using a variety of algorithms in CPU scheduling. First come first serve (FCFS), Shortest Job First (SJF), Shortest Remaining Time First (SRTF), Priority Scheduling, Round Robin (RR), Multi-Level Queue (MLQ), and Multi-Level Feedback Queue (MLFQ) are just a few of the scheduli
3 min read
Shortest Job First or SJF CPU Scheduling Shortest Job First (SJF) or Shortest Job Next (SJN) is a scheduling process that selects the waiting process with the smallest execution time to execute next. This scheduling method may or may not be preemptive. Significantly reduces the average waiting time for other processes waiting to be execute
4 min read
Difference between First Come First Served (FCFS) and Round Robin (RR) Scheduling Algorithm First Come First Served Scheduling Algorithm: First Come First Served (FCFS) is the simplest and non-preemptive scheduling algorithm. In First Come First Served (FCFS), the process is allocated to the CPU in the order of their arrival. A queue data structure is used to implement the FCFS scheduling
2 min read
Longest Job First (LJF) CPU Scheduling Algorithm Longest Job First (LJF) is a non-preemptive scheduling algorithm. This algorithm is based on the burst time of the processes. The processes are put into the ready queue based on their burst times i.e., in descending order of the burst times. As the name suggests this algorithm is based on the fact t
5 min read
Difference between First Come First Served (FCFS) and Longest Job First (LJF) CPU scheduling algorithms 1.First Come First Served (FCFS) : First Come First Served (FCFS) is the simplest type of algorithm. It is a non-preemptive algorithm i.e. the process cannot be interrupted once it starts executing. The FCFS is implemented with the help of a FIFO queue. The processes are put into the ready queue in
3 min read