# Understanding FCFS Scheduling Algorithms in Operating Systems (OS) with Examples

FCFS (First-Come-First-Serve) scheduling algorithm is one of the basic scheduling algorithms used in operating systems. It is a non-pre-emptive scheduling algorithm that schedules the processes in the order in which they arrive in the ready queue. In this article, we will discuss the FCFS scheduling algorithm in detail, its advantages and disadvantages, and provide examples to illustrate how it works.

### How does FCFS scheduling algorithm work?

In the FCFS scheduling algorithm, the process that arrives first gets executed first. Once the CPU starts executing a process, it continues to do so until the process completes its execution or blocks for some input/output operation. The next process in the ready queue is then selected for execution.
Let's take an example to understand this better. Consider the following set of processes with their arrival times and burst times:

### Calculate Average Waiting time and Average TAT Using FCFS algorithm for given schedule:

The FCFS scheduling algorithm will schedule these processes in the order in which they arrive. The Gantt chart for these processes would look like this:
As we can see, process P1 arrives at time 0 and is executed first. It completes its execution at time 4. Then, the process P2 arrives at time 2 and is executed next. Similarly, the processes P3 and P4 arrive at times 3 and 5, respectively, and are executed in the order in which they arrive.
Solution:
Job Arrival Time Burst Time Finish Time Turnaround Time Waiting Time
P1 0 4 4 4 0
P2 2 3 7 5 2
P3 3 2 9 6 4
P4 5 1 10 5 4
Average 20 / 4 = 5 10 / 4 = 2.5