Ex No: 7 Date: Write A Program For Implementing The FCFS Scheduling Algorithm
Ex No: 7 Date: Write A Program For Implementing The FCFS Scheduling Algorithm
Ex No: 7 Date: Write A Program For Implementing The FCFS Scheduling Algorithm
EX NO: 7
Date:
ALGORITHM:
1. Start the process.
2. Declare the array size.
3. Get the number of elements to be inserted.
4. Select the process that first arrived in the ready queue
5. Make the average waiting the length of next process.
6. Start with the first process from it’s selection as above and let other process to
be in queue.
7. Calculate the total number of burst time.
8. Display the values.
9. Stop the process.
PROGRAM:
#include<stdio.h>
main()
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
scanf("%d",&n);
printf("\n\n Enter the NAME , BURST TIME and ARRIVAL TIME of the
process");
for(i=0;i<n;i++)
scanf("%s",&pname[i]);
scanf("%d",&bt[i]);
scanf("%d",&at[i]);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(at[i]>at[j])
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
wt[0]=0;
for(i=0;i<n;i++)
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i]-at[i]);
sbt=sbt+(wt[i+1]-at[i]);
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
avgwt=(float) sum/n;
avgtt=(float)sbt/n;
for(i=0;i<n;i++)
printf("|\t%s\t",pname[i]);
printf("\n");
for(i=0;i<n;i++)
printf("%d\t\t",wt[i]);
printf("%d\n",ss);
printf("\n");
OUTPUT:
RESULT:
Thus the program for implementing FCFs scheduling algorithm was written and
successfully executed.