# First Come First Served (FCFS) Scheduling Algorithm

## It is a scheduling algorithm of an operating system

FCFS First Come First Served

Criteria:

• The process that requests first is served first. It means that processes are served in the exact order as they come.

Decision Mode:

• Non-preemptive: Once a process is selected, it runs until it blocks for an I/O or some event, or it terminates.

Implementation:

• This strategy can be easily implemented by using FIFO. FIFO means First In First Out.
• When the first process enters in the system, it starts execution.
• and the other processes are appended in a queue. When CPU becomes free, a process from the first position in the queue is selected to run.
• For finding Completion time, looking in Gantt chart from the back and complete of each process is completion time.
• Turn Around Time = Completion Time – Arrival Time.
• Waiting Time = Turn Around Time – Burst Time.

Now, see one example for a better understanding of it.

For Example:

 Process Arrival Time (A.T.) Burst Time (B.T.) P0 0 10 P1 1 6 P2 3 2 P3 5 4

In this example,

• we can see that process P0 arrives first so we have to give execution first to process P0.
• process P0 has 10 burst time so it is executed till the 0 to 10 because of Non-preemptive.
• After the execution of P0, all processes arrive but P1 has arrived first and after that P2 and after that P3 is arrived.
• so we have to give execution to P1 after that P2 and P3.

Gantt Chart: Table:

 Process Arrival Time Burst Time Completion Time Turnaround Time Waiting Time P0 0 10 10 10 0 P1 1 6 16 15 9 P2 3 2 18 15 13 P3 5 4 22 17 13

Average Turnaround Time:(10+15+15+17)/4 = 14.25

Average Waiting Time: (0+9+13+13)/4 = 8.75

Throughput: 0.181818

• Simple, no starvation
• Easy to understand and implement.

• Not efficient, average waiting time is too high.
• suffer from convoy effect.
• The utilization is low.

### Implementation of FCFS in C language:

`#include<stdio.h>int main(){int size;printf("Enter No. of Process : ");scanf("%d",&size);int p[size],at[size],bt[size],wt[size],ct[size],tat[size],i,j,gc=0,temp=0,ttat=0,twt=0;float atat=0,awt=0,tp=0;printf("\nEnter the arrival time :\n");for(i=0;i<size;i++){p[i]=i;scanf("%d",&at[i]);}printf("\nEnter the Burst time :\n");for(i=0;i<size;i++){scanf("%d",&bt[i]);}printf("Applying FCFS-\n");for(i=0;i<size;i++){for(j=0;j<size-i-1;j++){if(at[j+1]<at[j]){temp=at[j];at[j]=at[j+1];at[j+1]=temp;temp=0;temp=p[j];p[j]=p[j+1];p[j+1]=temp;temp=0;temp=bt[j];bt[j]=bt[j+1];bt[j+1]=temp;}}}for(i=0;i<size;i++){ct[i]=gc+bt[i];gc=ct[i];tat[i]=ct[i]-at[i];wt[i]=tat[i]-bt[i];ttat=ttat+tat[i];twt=twt+wt[i];}atat=(float)ttat/size;awt=(float)twt/size;tp=(float)size/gc;printf("P.no.\tAT\tBT\tCT\tWT\tTAT");for(i=0;i<size;i++){printf("\n%d\t%d\t%d\t%d\t%d\t%d",p[i],at[i],bt[i],ct[i],wt[i],tat[i]);}printf("\nAvg. Turn Around time= %.2f",atat);printf("\nAvg. Waiting time= %.2f",awt);printf("\nThrough put= %.4f",tp);}`

Comment for any query.
https://www.geeksforgeeks.org/program-fcfs-scheduling-set-1/

For Android projects goto the ANDROID

Stay Connect with our app: –