#include<stdio.h>
#include<conio.h>
#define max 10
int i,j,qt,nop;
struct process
{
int ind;
int prn;
int bt;
int wt;
int tt;
}pr[max],temp;
void ins_dat()
{
for(i=0;i<nop;i++)
{
pr[i].prn = i+1;
printf("\n Enter the Burst time of Process #%d : ",pr[i].prn);
scanf("%d",&pr[i].bt);
pr[i].ind = pr[i].wt = pr[i].tt = 0;
}
}
void Round_Robin()
{
printf("\n\n Process Burst Time Waiting Time Turnaround Time \n");
printf(" ------------------------------------------------------- \n");
int done = 0,ttl_tt=0,ttl_wt=0;
float avg_tt,avg_wt;
temp = pr[0];
i = 0;
do
{
if(pr[i].ind == 0)
{
printf(" %d \t\t %d \t\t",pr[i].prn,pr[i].bt);
pr[i].wt += (temp.tt - pr[i].tt);
if(qt >= pr[i].bt)
{
pr[i].tt = temp.tt + pr[i].bt;
pr[i].bt = 0;
pr[i].ind = 1;
done ++;
ttl_wt += pr[i].wt;
ttl_tt += pr[i].tt;
}
else
{
pr[i].bt -= qt;
pr[i].tt = temp.tt + qt;
}
temp = pr[i%nop];
printf(" %d \t\t %d\n\n",pr[i].wt,pr[i].tt);
}
i = (i+1)%nop;
}while(done != nop);
avg_wt = (float) ttl_wt/nop;
avg_tt = (float) ttl_tt/nop;
printf("\n\n Average Waiting Time : %f",avg_wt);
printf("\n Average Turnaround Time : %f",avg_tt);
}
void main()
{
do
{
clrscr();
printf("\n Enter the number of processes : ");
scanf("%d",&nop);
}while(nop > max || nop <= 0);
printf("\n Enter the Quantum time : ");
scanf("%d",&qt);
ins_dat();
Round_Robin();
getch();
}
No comments:
Post a Comment