Simulate the following CPU scheduling algorithms Round Robin

  #include<stdio.h>

#include<conio.h>
#include<math.h>
void main()
{
 char pname[20][10];
 int n,i,bt[20],ptime[20],tq,count=0,tot=0,wt[20],twt=0,ttt=0,e[20];
 float awt,att;
 clrscr();
 printf("enter number of process : ");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
 printf("enter %d process name : ",i);
 scanf(" %s",pname[i]);
 printf("enter %d process time : ",i);
 scanf("%d",&ptime[i]);
 bt[i]=ptime[i];
 }
 printf("enter time quantum : ");
 scanf("%d",&tq);
 while(count<n)
 {
for(i=1;i<=n;i++)
{
if(bt[i]!=0)
{
if(bt[i]<=tq)
{
tot+=bt[i];
bt[i]=0;
e[i]=tot;
count++;
}
else
{
bt[i]=bt[i]-tq;
tot+=tq;
}
printf("%s\t%d\n",pname[i],bt[i]);
}
}
 }
for(i=1;i<=n;i++)
{
wt[i]=e[i]-ptime[i];
twt+=wt[i];
ttt+=e[i];
}
printf("pname\tcpu time\twaiting time\tturn around time");
for(i=1;i<=n;i++)
printf("\n%s\t\t%d\t\t%d\t\t%d",pname[i],ptime[i],wt[i],e[i]);
printf("\ntotal waiting time : ");
printf("%d",twt);
awt=(float)twt/n;
printf("\naverage waiting time : ");
printf("%f",awt);
printf("\ntotal turn around time : ");
printf("%d",ttt);
att=(float)ttt/n;
printf("\naverage turn around time : ");
printf("%f\n",att);
getch();
}

Comments

Popular posts from this blog

CLOOK DISK SCHEDULING

LOOK Disk Scheduling