Aim: Write A C Program To Implement Round Robin Scheduling Algorithm Source Code
Aim: Write A C Program To Implement Round Robin Scheduling Algorithm Source Code
Source Code:
#include<stdio.h>
int main()
{
int pno[5],bt[5],wt[5],tat[5],ts,np;
oat awt,atat;
int ag=0,twt=0,ttat=0,i,j,k,temp,t[5];
printf("Round robin Scheduling\n\n");
for(i=0;i<np;i++)
{
printf("Enter the processor no,service time for process %d:",i);
scanf("%d%d",&pno[i],&bt[i]);
}
for(i=0;i<np;i++)
{
wt[i]=0;
t[i]=bt[i];
}
while(1)
{
for(i=0;i<np;i++)
{
if(bt[i]!=0)
{
if(bt[i]<ts)
{
temp=bt[i];
bt[i]=0;
ag= ag+1;
}
else
{
temp=ts;
bt[i]=bt[i]-ts;
if(bt[i]==0)
{
ag = ag+1;
fl
fl
fl
fl
fl
fl
}
}
for(k=0;k<np;k++)
{
if(k!=i)
{
if(bt[k]!=0)
{
wt[k]=wt[k]+temp;
}
}
}
}
}
if( ag==np)
{
break;
}
}
for(i=0;i<np;i++)
{
tat[i]=t[i]+wt[i];
twt=twt+wt[i];
ttat=ttat+tat[i];
}
awt=( oat)twt/np;
atat=( oat)ttat/np;
printf("PNO BT WT TAT\n");
for(i=0;i<np;i++)
{
printf("%d\t%d\t%d\t%d\n",pno[i],t[i],wt[i],tat[i]);
}