Pages

Tuesday, 5 February 2019

Program on CPU SCHEDULING - First Come First Serve (NON PREEMPTIVE)

/*  Program to Implement FIRST COME FIRST SERVE CPU Scheduling */

#include<stdio.h>
void main()
{
   int p[10],bt[10],st[10],ct[10],tat[10],wt[10],i,n;
   float sumtat=0,sumwt=0,avwt,avtat;
   printf("\n enter the no of processes");
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
     printf("\n enter the process no and burst time ");
     scanf("%d %d",&p[i],&bt[i]);
   }
   st[0]=0;
   wt[0]=0;
   ct[0]=st[0]+bt[0];
   for(i=0;i<n;i++)
   {
     st[i+1]=st[i] + bt[i];
     ct[i+1]=st[i+1]+ bt[i+1];
   }
   for(i=0;i<n;i++)
   {
     tat[i]=ct[i]-0;
     sumtat=sumtat + tat[i];
   }
   for(i=0;i<n;i++)
   {
     wt[i]=tat[i]-bt[i];
     sumwt=sumwt + wt[i];
   }
  printf("\n\t Pno\tbt\tst\tct\ttat\twt\n");
  for(i=0;i<n;i++)
  {
   printf("\n\t%d\t%d\t%d\t%d\t%d\t%d",p[i],bt[i],st[i],ct[i],tat[i],wt[i]);
  }
  avtat=sumtat/n;
  avwt=sumwt/n;
  printf("\n avearge waiting time is %f\n",avwt);
  printf("\n average turnaroundtime is %f\n",avtat);
}

output:

No comments:

Post a Comment