Wednesday, 8 February 2017

C Program for implementing FCFS (Operating System Scheduling Algorithm)

First Come First Served (FCFS) is an Operating System process scheduling algorithm. It is non-preemptive in scheduling algorithm. Jobs are executed on first come, first serve basis. It is easy to understand and implement but poor in performance, as average wait time is high. C program is given below to show the implementation of the FCFS process scheduling algorithm.


#include <stdio.h>
int main()
{
         int bt[20],wt[20],tat[20],avwt=0;
         int i,j,n;

         printf("\nEnter the number of the processes: ");
         scanf("%d",&n);

         for(i=0;i<n;i++)
         {
                printf("\nEnter the burst time of the process %d: ",i);
                scanf("%d",&bt[i]);
         }

         wt[0]=0;
         tat[0]=bt[0];

         for(i=1;i<n;i++)
         {
               wt[i]=wt[i-1]+bt[i-1];
               tat[i]=tat[i-1]+bt[i];
               avwt+=wt[i];
         }
         avwt=avwt/n;
        printf("\n\nPROCESS\twaiting time\tburst time\tTurnaround time\n");
        printf("\n");
        for(i=0;i<n;i++)
        {
               printf("P%d\t\t%d\t\t%d\t\t%d\n",i,wt[i],bt[i],tat[i]);
        }
        printf("\n\nAverage waiting time: %d",avwt);
        return 0;
}                                                                                                                                                     

Output:

1 comments so far

it was quite good and may be excellent if comment lines are written


EmoticonEmoticon