First-come, first-served (FCFS) – sometimes first-in, first-served and first-come, first choice – is a service policy whereby the requests of customers or clients are attended to in the order that they arrived, without other biases or preferences. The policy can be employed when processing sales orders, in determining restaurant seating, on a taxi stand, etc. In Western society, it is the standard policy for the processing of most queues in which people wait for a service that was not prearranged or preplanned.
Festival seating (also known as general seating and stadium seating) is seating done on an FCFS basis. (See The Who concert disaster for details on a December 1979 disaster involving "festival seating" at a concert by The Who in Cincinnati, Ohio at the River front Coliseum.) The practice is also common among some airlines which do not permit seat reservations either in advance or at check-in. These airlines allow passengers to board in small groups based upon their order of check-in and sit in whatever seat on the aircraft they wish to. On the basis of first come, first served, the earlier they check in, the earlier they board the aircraft to get the seat they want. Passengers are sequentially (on a first come, first served basis) assigned into one of several "boarding groups." The passengers are then boarded onto the plane in group order.
Service and events which are scheduled often use a different service policy; e.g., a restaurant may take reservations for parties in advance; when such a party arrives at the designated time, it can be seated immediately at a reserved table.
/* FIRST COME FIRST SERVED SCHEDULING ALGORITHM*/
//PREPROCESSOR DIRECTIVES
#include<stdio.h>
#include<conio.h>
#include<string.h>
//GLOBAL VARIABLES - DECLARATION
int n,Bu[20],Twt,Ttt,A[10],Wt[10],w;
float Awt,Att;
char pname[20][20],c[20][20];
//FUNCTION DECLARATIONS
void Getdata();
void Gantt_chart();
void Calculate();
void fcfs();
//GETTING THE NUMBER OF PROCESSES AND THE BURST TIME AND ARRIVAL TIME FOR EACH PROCESS
void Getdata()
{
int i;
printf("\n Enter the number of processes: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fflush(stdin);
printf("\n\n Enter the process name: ");
scanf("%s",&pname[i]);
printf("\n Enter The BurstTime for Process %s = ",pname[i]);
scanf("%d",&Bu[i]);
printf("\n Enter the Arrival Time for Process %s = ",pname[i]);
scanf("%d",&A[i]);
}
}
//DISPLAYING THE GANTT CHART
void Gantt_chart()
{
int i;
printf("\n\n\t\t\tGANTT CHART\n");
printf("\n-----------------------------------------------------------\n");
for(i=1;i<=n;i++)
printf("|\t%s\t",pname[i]);
printf("|\t\n");
printf("\n-----------------------------------------------------------\n");
printf("\n");
for(i=1;i<=n;i++)
printf("%d\t\t",Wt[i]);
printf("%d",Wt[n]+Bu[n]);
printf("\n-----------------------------------------------------------\n");
printf("\n");
}
//CALCULATING AVERAGE WAITING TIME AND AVERAGE TURN AROUND TIME
void Calculate()
{
int i;
//For the 1st process
Wt[1]=0;
for(i=2;i<=n;i++)
{
Wt[i]=Bu[i-1]+Wt[i-1];
}
for(i=1;i<=n;i++)
{
Twt=Twt+(Wt[i]-A[i]);
Ttt=Ttt+((Wt[i]+Bu[i])-A[i]);
}
Att=(float)Ttt/n;
Awt=(float)Twt/n;
printf("\n\n Average Turn around time=%3.2f ms ",Att);
printf("\n\n AverageWaiting Time=%3.2f ms",Awt);
}
//FCFS Algorithm
void fcfs()
{
int i,j,temp, temp1;
Twt=0;
Ttt=0;
Printf("\n\n FIRST COME FIRST SERVED ALGORITHM\n\n");
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(A[i]>A[j])
{
temp=Bu[i];
temp1=A[i];
Bu[i]=Bu[j];
A[i]=A[j];
Bu[j]=temp;
A[j]=temp1;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}
}
}
Calculate();
Gantt_chart();
}
void main()
{
int ch;
clrscr();
Getdata();
fcfs();
getch();
}
Comments
Post a Comment