Monday, 25 March 2013

Round Robin Scheduling in C Programming

Round Robin Technique is one of the scheduling algorithm for processes in an operating system. This algorithm give the CPU access to a process for a particular time period which time know as Quantum Time. After execution once all the process again repeated and allotted for CPU execution that’s why it’s Round term us in this algorithm. I made following Program which manage all the process and calculate average turn around time and waiting time.

Source Code :

<pre class="brush : cpp">
#include<stdio.h>
#include<conio.h>
int 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;
printf("enter number of processes : ");
scanf("%d", &n);
printf("nenter burst time for processes ");
for(i=0; i<n;i++)
{
printf("nFor process p%d : ",i+1); 
scanf("%d", &bt[i]);
st[i]=bt[i];
}
printf("nenter time quantum : ");
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_not burst_timet wait_timet turn_around_time");
for(i=0; i<n; i++)
{
printf("n%dtt %dtt %dtt %d", i+1, bt[i], wt[i], tat[i]);
}
printf("naverage wait time is %fnaverage turn_around_time is %fn", awt, atat);
getch();
return 0;}
</pre>


Output :




1 comment: