Implementation of Round Robin Scheduling Algorithm

Source code Round Robin Programming Algorithm
#include<stdio.h>
int ttime,i,j,temp;
main()
{
int pname[10],btime[0],
pname2[10],btime2[10];
int n,x,z;
printf("enter the no of process");
scanf("%d",&n);
printf("Enter the process name & burst time for the process\n");
for(i=0;i<n;i++)
{
printf("Enter the process name");
scanf("%d",&pname2[i]);
printf("Enter the burst time for the process %d");
scanf("%d",&btime2[i]);
}
printf("PROCESS NAME\t\tBURST TIME");
for(i=0;i<n;i++)
printf("%d\t\t\t%d\n",pname2[i],btime[i]);
z=1;
while(z==1)
{
ttime=0;
for(i=0;i<n;i++)
{
pname[i]=pname2[i];
btime[i]=btime2[i];
}
printf("\npress 1.roundrobin \n2.exit");
scanf("%d",&x);
switch(x)
{
case 1:
rrobin(pname,btime,n);
break;
case 2:
exit(0);
break;
}
printf("\n\n if you want to continue press1:");
scanf("%d",&z);
}
}
rrobin(int pname[],int btime[],int n)
{
int tslice;
j=0;
printf("\n\t round robin scheduling");
printf("enter the time slice");
scanf("%d",&tslice);
printf("process name\t remaining time \ttotal time");
while(j<n)
{
for(i=0;i<n;i++)
{
if(btime[i]>0)
{
if(btime[i]>=tslice)
{
ttime+=tslice;
btime[i]=btime[i]-tslice;
printf(“\n %d\t\t%d\t\t%d”,pname[i],btime[i],ttime);
if(btime[i]==0)
j++;
}
else
{
ttime+=btime[i];
btime[i]=0;
printf(“\n %d\t\t%d\t\t%d”,pname[i],btime[i],ttime);
}
}
}
}
}

OUTPUT CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ cc rr.c
[redhat35@localhost Rhel5]$ ./a.out
Enter the number of process: 3
Enter the process name and burst time for the process
Enter the process name 1
Enter the burst time for the process: 1
10
Enter the process name 2
Enter the burst time for the process: 2
10
Enter the process name 3
Enter the burst time for the process: 3
10
Press 1.round robin
2.exit
1
Process name Remaining time Total
1 5 5
2 5 10
3 5 15
1 0 20
2 0 25
3 0 30
If you want to continue press 1
0

Related post