FCFS

SCHEDULING ALGORITHMS

First Come First Serve 


// Program

// 1. FCFS scheduling

#include<stdio.h>

#include<stdlib.h>

 

typedef struct process

{

int pid,ft,wt,bt;

}pr;

pr p[10];

int n;

void fcfs();

void disp_gantt();

 

int main()

{

int i;

printf(“\nHow many processes : “);

scanf(“%d”,&n);

printf(“\tEnter the values for Burst time\n”);

for(i=0;i<n;i++)

{

printf(“\tEnter for Process %d : “,i);

scanf(“%d”,&p[i].bt);

p[i].pid=i;

}

fcfs();

}

void fcfs()

{

int i,j;

float avgwt, avgtat, sum_wt=0, sum_tat=0;

for(i=0;i<n;i++)

{

if(i==0)

p[i].wt=0;

else

p[i].wt=p[i-1].ft;

p[i].ft=p[i].wt+p[i].bt;

sum_wt=sum_wt+p[i].wt;

sum_tat=sum_tat+p[i].ft;

}

avgwt=sum_wt/n;

avgtat=sum_tat/n;

 

disp_gantt(n);

printf(“\nAverage Turnaround Time : %5.2f ms”,avgtat);

printf(“\nAverage Waiting Time : %5.2f ms \n\n”, avgwt);

}

 

void disp_gantt()

{

int i;

printf(“\n\nGANTT CHART\n\n\t”);

for(i=0;i<n;i++)

printf(“P%d\t”,p[i].pid);

printf(“\n   0\t”);

for(i=0;i<n;i++)

printf(”    %d\t”,p[i].ft);

printf(“\n”);

}