About

WELCOME! Get Latest Tricks n Tips About Computers, Facebook, Internet and Everything Related...

Sunday, September 29, 2013

Program for Round Robin Scheduling Algorithm in C

Round robin is a CPU process scheduling algorithm. in this scheduling, cpu allots a fixed time slice or time quantum to each process in a queue. The process terminates, leaves the queue. 

#include<stdio.h>
#include<conio.h>
void main()
{
int st[10], bt[10], wt[10], tat[10], n, tq;
int i, count=0, swt=0, stat=0, temp, sq=0;
float awt=0.0, atat=0.0;    clrscr();
printf("Enter no. of processes (Gourav) : ");
scanf("%d", &n);
printf("\nEnter burst time for processes-- ");
for(i=0; i<n;i++)
{
printf("\nProcess P%d : ",i+1);
scanf("%d", &bt[i]);
st[i]=bt[i];
}
printf("\nEnter time slice : ");
scanf("%d", &tq);
while(1)
{
for(i=0, count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
{
st[i]=st[i]-tq;
}
else
if (st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf(" \n process no.  burst time   wait time   turn around time");
for(i=0; i<n; i++)
{
printf("\n%d\t\t %d\t\t %d\t\t %d", i+1, bt[i], wt[i], tat[i]);
}
printf("\naverage wait time is %fnaverage turn_around_time is %fn", awt, atat);
getch();
}

No comments:

Post a Comment