Thursday 29 September 2011


IMPLEMENTATION OF FCFS SCHEDULING

AIM:
To write a C Program to perform FCFS Scheduling in Linux.

ALGORITHM:

  1. Start the program.
  2. Read the number of requests
  3. Read the burst(execution) time for each process
  4. The processes are allowed to execute depends of the arrival time.
  5. The waiting time is calculated for all the process.
  6. The gantt chart is drawn representing the process execution.
  7. Calculate the waiting time and the turnaround time for all the process.
  8. Stop the process.

PROGRAM:

#include<stdio.h>
int  main()
{
int a[10],b[10],c[10],n,i,wt=0;
float avgwt;
a[0]=b[0]=0;
printf("\nEnter the no. of processes\t");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the burst time:");
scanf("%d",&a[i]);
}
printf("\n The entered process are");
for(i=1;i<=n;i++)
printf("\np%d %d",i, a[i]);
printf("\n The gantt chart is:\n");
for(i=1;i<=n;i++)
{
printf("\t p%d",i);
}
printf("\n");
printf("\t%d",b[0]);
for(i=1;i<=n;i++)
{
b[i]=a[i]+b[i-1];
printf("\t%d",b[i]);
}
printf("\n The waiting time is");
for(i=0;i<n;i++)
{
printf("\np%d\t%d",i+1,b[i]);
wt=b[i]+wt;
}
avgwt=wt/i;
printf("\nThe average waiting time is %f",avgwt);
printf("\nThe turnaround time is");
wt=0;
for(i=1;i<=n;i++)
{
printf("\np%d\t%d",i,b[i]);
wt=b[i]+wt;
}
avgwt=wt/i;
printf("\nThe average turnaround time is %f",avgwt);
printf("\n");
}

OUTPUT:
[root@localhost ~]# ./p5
Enter the no. of processes      4
Enter the burst time:4
Enter the burst time:3
Enter the burst time:2
Enter the burst time:5
The entered processes are
P1      4
P2       3
P3       2
P4       5
The gantt chart is:
P1       P2      P3       P4
0         4        7         9       14
The waiting time is
P1      0
P2      4
P3      7
P4      9
The average waiting time is 5.000000
The turnaround time is
P1      4
P2      7
P3      9
P4      14
The average turnaround time is 6.000000

0 comments:

Post a Comment