---
title: "Explain the First Come First Serve (FCFS) algorithm with an example in OS."  
description: "Explain the First Come First Serve (FCFS) algorithm with an example in OS."  
author: "Revati S Misra"  
published: 2023-03-31  
updated: 2023-04-20  
canonical: https://www.mindstick.com/forum/157666/explain-the-first-come-first-serve-fcfs-algorithm-with-an-example-in-os  
category: "Operating System"  
tags: ["windows", "operating system"]  
reading_time: 4 minutes  

---

# Explain the First Come First Serve (FCFS) algorithm with an example in OS.

What is the First Come First Serve (FCFS) [algorithm](https://www.mindstick.com/blog/119/implementing-cryptography-in-c-sharp-dot-net-by-using-sha1-algorithm) and why is it used in OS?

## Replies

### Reply by Aryan Kumar

First Come First Serve (FCFS) is a scheduling algorithm in Operating System where the processes are executed in the order they arrive. The process that arrives first will be executed first and so on. It is a non-preemptive scheduling algorithm, which means that once a process starts executing, it will not be interrupted until it completes.

Here is an example of FCFS scheduling algorithm:

Consider there are three processes P1, P2, and P3 with their arrival times and burst times given below:

| **Process** | **Arrival Time** | **Burst Time** |
| --- | --- | --- |
| P1 | 0 | 5 |
| P2 | 1 | 3 |
| P3 | 2 | 8 |

The Gantt chart for FCFS algorithm will be as follows:

| **P1** | **P2** | **P3** | **P3** | **P3** | **P3** | **P3** | **P3** | **P3** |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 0 | 5 | 8 | 16 | 24 | 32 | 40 | 48 | 56 |

The average waiting time and turnaround time for each process are as follows:

| **Process** | **Waiting Time** | **Turnaround Time** |
| --- | --- | --- |
| P1 | 0 | 5 |
| P2 | 4 | 7 |
| P3 | 9 | 17 |
| Average | 4.33 | 9.67 |

The Gantt chart shows the sequence in which the processes are executed. The waiting time for each process is the amount of time it spends waiting in the ready queue before it starts executing. The turnaround time for each process is the amount of time it takes to complete its execution from the time it arrives.

The average waiting time and turnaround time for all the processes are calculated by summing up the waiting time and turnaround time for each process and then dividing it by the number of processes.

FCFS is a simple and easy-to-understand scheduling algorithm. However, it is not suitable for systems with long-running processes or interactive systems where short response times are important. It also suffers from a problem called "convoy effect", where a long-running process can block the execution of short processes that arrive later.\

### Reply by Krishnapriya Rajeev

The First Come First Serve (FCFS) algorithm is a scheduling algorithm used by the operating system to allocate CPU time to processes. In this algorithm, the process that arrives first is assigned the CPU time first, and the process that arrives later is assigned the CPU time later. This algorithm is also known as the First-In-First-Out (FIFO) algorithm. It is non-preemptive.

Example:

Suppose there are three processes, P1, P2, and P3, that require CPU time to execute. The arrival time and burst time for each process are as follows:

| Process Name | Arrival time | Burst Time |
| --- | --- | --- |
| P1 | 0 | 3 |
| P2 | 1 | 2 |
| P3 | 3 | 1 |

The FCFS algorithm assigns the CPU time to the processes in the order they arrive. Therefore, the CPU time is first assigned to P1, then P2, and finally to P3. The Gantt chart for the execution of the processes using the FCFS algorithm is as follows:

```plaintext
	P1		P2		P3
_________________________
0		3		5		6
```

As you can see from the Gantt chart, P1 is assigned the CPU time first and executes for 3 units of time. Then, P2 is assigned the CPU time and executes for 2 units of time. Finally, P3 is assigned the CPU time and executes for 1 unit of time. The total waiting time for P1, P2, and P3 is 0, 3, and 5, respectively.

The FCFS algorithm is simple to implement and easy to understand. However, it may not be the best choice for scheduling processes when the processes have widely varying burst times.


---

Original Source: https://www.mindstick.com/forum/157666/explain-the-first-come-first-serve-fcfs-algorithm-with-an-example-in-os

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
