Skip to content

Commit 7f35408

Browse files
The code is to implement Round Robin/preemptive scheduling
Round Robin is a scheduling algorithm where time slices are divided for every activity/process. The tasks are performed recursively in those time slices as a loop until all tasks at hand are taken care of (are executed).
1 parent 8176e6c commit 7f35408

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

Roundrobin.c

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
=================================================================================================================================
2+
/*TIME COMPLEXITY
3+
TO PREFORM ROUNDROBIN*/
4+
5+
#include<stdio.h>
6+
#include<time.h>
7+
8+
int main()
9+
{
10+
int count,j,n,time,remain,flag=0,time_quantum;
11+
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
12+
clock_t s,end;
13+
float t;
14+
printf("Enter Total Process:\t ");
15+
scanf("%d",&n);
16+
remain=n;
17+
for(count=0;count<n;count++)
18+
{
19+
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
20+
scanf("%d",&at[count]);
21+
scanf("%d",&bt[count]);
22+
rt[count]=bt[count];
23+
}
24+
printf("Enter Time to be alloted for each job:\t");
25+
scanf("%d",&time_quantum);
26+
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
27+
start = clock(); //starting the clock
28+
for(time=0,count=0;remain!=0;)
29+
{
30+
if(rt[count]<=time_quantum && rt[count]>0)
31+
{
32+
time+=rt[count];
33+
rt[count]=0;
34+
flag=1;
35+
}
36+
else if(rt[count]>0)
37+
{
38+
rt[count]-=time_quantum;
39+
time+=time_quantum;
40+
}
41+
if(rt[count]==0 && flag==1)
42+
{
43+
remain--;
44+
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
45+
wait_time+=time-at[count]-bt[count];
46+
turnaround_time+=time-at[count];
47+
flag=0;
48+
}
49+
if(count==n-1)
50+
count=0;
51+
else if(at[count+1]<=time)
52+
count++;
53+
else
54+
count=0;
55+
}
56+
end=clock(); //end of clock time
57+
t=(float)(end-s)/CLOCKS_PER_SEC; //time elpased performing the task
58+
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
59+
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
60+
printf(“Avg time take by the algorithm : %f”,t);
61+
return 0;
62+
}
63+
64+
==========================================================================================================

0 commit comments

Comments
 (0)