Monday, February 1, 2010

FCFS Implementation in C


Hi friends, below is a code to implement FCFS in C language...

(code given may not be clear, you can however download the code itself by clicking the link below)

#include
#include
struct proc
{
char id[6];
int burst_time; /*Holds the burst time of the process*/
int wait_time; /*Holds the waiting time of the process*/
int turn_time; /*Holds the turnaround time of the process*/
}process[10];
main()
{
int no,i,tot_wait=0; //total waiting time
float avg_wait; //average waiting time
clrscr();
printf("\n Enter the Number of Processes:");
scanf("%d",&no);
for(i=0;i {
printf("\n Enter the process id:");
scanf("%s",process[i].id);
printf("\n Enter the burst time:");
scanf("%d",&process[i].burst_time);
process[i].wait_time = 0;
}
// Gantt chart display
printf("\n\n Gantt Chart:\n\n");
printf("\n %s - %d to %d",process[0].id,process[0].wait_time,process[0].burst_time);
process[0].turn_time = process[0].wait_time + process[0].burst_time;
for(i=1;i {
process[i].wait_time = process[i-1].wait_time + process[i-1].burst_time;
process[i].turn_time = process[i].wait_time + process[i].burst_time;
printf("\n %s - %d to %d",process[i].id,process[i].wait_time,process[i].turn_time);
}


//Process,waiting time, turnaround time display
printf("\n\n Process \t Waiting Time \t Turnaround time");
for(i=0;i {
printf("\n%s\t\t%d\t\t%d",process[i].id,process[i].wait_time,process[i].turn_time);
tot_wait = tot_wait + process[i].wait_time;
}
avg_wait = tot_wait / no;
printf("\n\n The average waiting time is %f",avg_wait);
getch();
}




Download Source Code

By G.Vivek Venkatesh

the code has been written so that there is no error...in case u find any error pls let me know...

No comments: