UNIX C Program for Round Robin Scheduling Algorithm | CS1254-Operating Systems Lab

AIM:
To write a LINUX/UNIX C Program for the Implementation of Round Robin Scheduling Algorithm in CS1254 - Operating Systems Laboratory.

SOURCE CODE:
#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:
[examuser35@localhost Jebastin]$ cc rr.c
[examuser35@localhost Jebastin]$ ./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
Previous
Next Post »

2 comments

Write comments
Jon Mathu
AUTHOR
January 11, 2014 at 8:10 AM delete

Wonderful site. I enjoyed this siteScheduling Software

Reply
avatar
Jon Mathu
AUTHOR
January 11, 2014 at 12:43 PM delete

yesta desamba Thank you for your commentScheduling Software

Reply
avatar

If you still didn't find what you're looking for, you can search this website below: