Skip to main content

FIRST COME FIRST SERVED SCHEDULING ALGORITHM

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

Popular posts from this blog

Login and Registration Example in JSP with Session

Those who want to start with jsp and MySQL, this is an excellent example for themselves. Here you can learn how to insert data to MySQL using JSP. Also you can learn about session handling in jsp. 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `members` (    `id` int (10) unsigned NOT NULL auto_increment,    `first_name` varchar (45) NOT NULL ,    `last_name` varchar (45) NOT NULL ,    `email` varchar (45) NOT NULL ,    `uname` varchar (45) NOT NULL ,    `pass` varchar (45) NOT NULL ,    `regdate` date NOT NULL ,    PRIMARY KEY   (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; index.jsp 1 2 3 4 5 6 ...

Timer funcitons in JavaScript: Reminder Script

Timers are used in web pages and we will discuss how to setup one and how to use one with an example. The function setTimeout() in function is used and here is its general syntax. mytime = setTimeout(expression, msec); mytime  is the identifier used to identify the current timeout function.  expression  is the statement that is to be executed after the specified time has ticked off.  msec  is the duration of time in milliseconds after which the expression will be executed.  You can see by using setTimeout function we can execute any function or object after a set of time. For example if msec is set 5000 then the expression will be executed after 5 seconds or 5000 milliseconds.  We will try one example where we will have four period buttons and each button will set a different time for another function to execute and display a alert button. We will call it as a reminder script and we will get one alert box based on the period button we click...

Binary Addition

/* File Name : BinAdd.java */    import java.util.*; public class BinAdd    {  public static String addBit(String a, String b, String c)  { String r=""; if(a.equals("1") && b.equals("0") || a.equals("0") && b.equals("1")) { if( c.equals("0")) r="1"; else { r="0"; c="1"; } } else if( a.equals("0") && b.equals("0") ) { if(c.equals("0")) r="0"; else r="1"; } else if( a.equals("1") && b.equals("1") ) { if(c.equals("0")){ r="0"; c="1"; } else { r="1"; c="1"; } } return c+r; }   public static String add(String a, String b)   { String r=""; int len=a.length(); String carry="0"; for(int i=len-1;i...

Real time changing Clock showing date and time

We can display a clock which will be showing the local time of the client computer by using JavaScript. Note that this time displayed is taken from user computer and not from the server.  We have seen in our  date object example how to display current date and time   where the current date and time is displayed once. Here we will try to display changing clock or real time change in date and time by using  setTimeout function . This setTimeout function we have used to trigger the time display function in a refresh rate of 1000 mill seconds ( 1 Sec ). This refresh rate can be changed to any other value. By changing the value to 5000 the clock will refresh and show the exact time once in every 5 seconds.  Here is the demo of this script and code is given below that.  Sat Apr 23 2016 08:27:22 GMT+0530 (IST)   Here is the code <html> <head> <title>(Type a title for your page here)</title> <script type="text/javascript...