Google Ads

Monday, July 27, 2009

ROUND ROBIN SCHEDULING

ROUND ROBIN SCHEDULING

Previous Next

#include”stdio.h”
void main()
{
int ts,pid[10],need[10],wt[10],tat[10],i,j,n,n1;
int bt[10],flag[10],ttat=0,twt=0;
float awt,atat;
clrscr();
printf("\t\t ROUND ROBIN SCHEDULING \n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~ \n\n");
printf("Enter the number of Process-->");
scanf("%d",&n);

n1=n;
printf("\n Enter the Timeslice-->");
scanf("%d",&ts);
for(i=1;i<=n;i++) { printf("\n Enter the process ID %d-->",i);
scanf("%d",&pid[i]);
printf("\n Enter the Burst Time for the process-->");
scanf("%d",&bt[i]);
need[i]=bt[i];
}
for(i=1;i<=n;i++) { flag[i]=1; wt[i]=0; } while(n!=0) { for(i=1;i<=n;i++) { if(need[i]>=ts)
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
wt[j]+=ts;
}
need[i]-=ts;
if(need[i]==0)
{
flag[i]=0;
n--;
}
}
else
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
wt[j]+=need[i];
}
need[i]=0;
n--;
flag[i]=0;
}
}
}
for(i=1;i<=n1;i++)
{
tat[i]=wt[i]+bt[i];
twt=twt+wt[i];
ttat=ttat+tat[i];
}
awt=(float)twt/n1;
atat=(float)ttat/n1;

printf("\n\n ROUND ROBIN SCHEDULING ALGORITHM\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\n\n Process \t ProcessID \t BurstTime \t WaitingTime \t TurnaroundTime \n ");
for(i=1;i<=n1;i++)
{
printf("\n %5d \t\t %5d \t\t %5d \t\t %5d \t\t %5d \n", i,pid[i],bt[i],wt[i],tat[i]);
}

printf("\n The average Waiting Time=%3.2f",awt);
printf("\n\n The average Turn around Time=%4.2f",atat);
getch();
}

No comments:

Post a Comment