Open In App

FCFS - First Come First Serve CPU Scheduling

Last Updated : 11 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  1. Arrival: Processes enter the system and are placed in a queue in the order they arrive.
  2. 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.
  3. 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:

  1. P1 will start first and run for 5 units of time (from 0 to 5).
  2. P2 will start next and run for 3 units of time (from 5 to 8).
  3. 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

ProcessesATBTCTTATWT
P10555-0 = 55-5 = 0
P20388-0 = 88-3 = 5
P3081616-0 = 1616-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

ProcessBurst Time (BT)Arrival Time (AT)
P15 ms2 ms
P23 ms0 ms
P34 ms4 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:

ProcessCompletion Time (CT)Turnaround Time (TAT = CT - AT)Waiting Time (WT = TAT - BT)
P23 ms3 ms0 ms
P18 ms6 ms1 ms
P312 ms8 ms4 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.

Next Article
Practice Tags :

Similar Reads