First Come First serve is a Processes scheduling algorithm in which the process which arrives first gets System Resources First.The process with the least arrival time gets the system system resources first followed by processes with higher arrival time.
Waiting Time:
The Time Process has to wait in the ready list to get the system resources for its execution
Execution Time:
The time the process requires to perform the computation.
Turn Around Time:
The Total Time the Process Requires for completion waiting time+Execution Time
The following is a C Program Source Code of a First Come First Serve algorithm implementation.The processes are scheduled according to the arrival time and finally the waiting time and turn around time of the processes are calculated.
#include<stdio.h>
void main()
{
int i,ex[20],tr[20],wt[20],n,ar[20];
int j,k,temp,od[20];
float b=0,c=0;
printf("\n Enter the number of processes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf(" P%d = ",i+1);
printf("\n Excecution time : ");
scanf(" %d",&ex[i]);
printf("\n Arrival time : ");
scanf("%d",&ar[i]);
}
for(i=0;i<n;i++)
od[i]=ar[i];
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(ar[i]>ar[j])
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
}
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if(ar[j]==od[i])
{
if(j==0)
{
wt[i]=ar[j];
b=wt[i];
tr[i]=ex[i];
c=tr[i];
break;
}
wt[i]=temp-ar[j]+ar[j-1];
b=b+wt[i];
tr[i]=ex[i]+wt[i];
c=c+tr[i];
break;
}
}
temp=tr[i];
}
b=b/n;
c=c/n;
printf("\n ORDER NAME ARRIVAL-TIME EX.TIME WAITING-TIME TURN-AROUND-TIME \n");
for(j=0;j<n;j++)
for(i=0;i<n;i++)
{
if(ar[j]==od[i])
{
printf(" %d P%d\t %d %d\t %d\t\t %d ",j+1,i+1,ar[j],ex[i],wt[i],tr[i]);
printf("\n");
break;
}
}
printf("Average waiting time = %f \n Average turn around time = %f \n",b,c);
}