First Come First Served (FCFS) Scheduling Algorithm

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:

first come first serve

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

Advantages:

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

Disadvantages:

  • 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.
To learn more concept about FCFS go to 
https://www.geeksforgeeks.org/program-fcfs-scheduling-set-1/

For Android projects goto the ANDROID

Stay Connect with our app: – 

https://play.google.com/store/apps/details?id=com.edu.easyengineer

For Assignment Questions and Explanation of a theory topic visit:

http://mycandal.com/home/elementor-179/

About easyengineering 32 Articles
Easyengineering.in provides you to all subject and exam related materials online like GPSC, UPSC, IES, GATE, etc. As well as we provide daily job notification, some life-related books and other online courses which are useful too in your study.

Be the first to comment

Leave a Reply

Your email address will not be published.


*