-
Notifications
You must be signed in to change notification settings - Fork 28
/
roundrobin.c
76 lines (63 loc) · 1.8 KB
/
roundrobin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Round-robin
#include <stdio.h>
int main()
{
int n,x,i, tq, total = 0,counter=0;
printf(" -------Round-robin Scheduling ------\n");
printf("\nEnter the No. of processes :");
scanf("%d", &n);
printf("Enter the time quanta: ");
scanf("%d",&tq);
int p[n], bt[n], wt[n], tat[n], ct[n],rem_bt[n],a[n];
printf("\nEnter the Arrival time and Burst time of each process :\n");\
for (int i = 0; i < n; i++)
{
printf("P[%d]: ",i+1);
scanf("%d %d", &a[i], &bt[i]);
rem_bt[i] = bt[i];
}
x=n;
for(total = 0, i = 0; x != 0;)
{
if(rem_bt[i] <= tq && rem_bt[i] > 0)
{
total = total + rem_bt[i];
rem_bt[i] = 0;
counter = 1;
}
else if(rem_bt[i] > 0)
{
rem_bt[i] = rem_bt[i] - tq;
total = total + tq;
}
if(rem_bt[i] == 0 && counter == 1)
{
x--;
printf("\n Process ID \t Burst Time \t Turnaround Time \t Waiting Time");
printf("\n Process[%d] \t\t %d \t\t %d \t\t %d", i + 1, bt[i], total - a[i], total - a[i] - bt[i]);
wt[i] = wt[i] + total - a[i] - bt[i];
tat[i] = tat[i] + total - a[i];
counter = 0;
}
if(i == n - 1)
{
i = 0;
}
else if(a[i + 1] <= total)
{
i++;
}
else
{
i = 0;
}
}
int wait_time =0;
int t_at = 0;
for(int j =0; j<n;j++)
{
t_at = t_at +tat[i];
wait_time = wait_time + wt[i];
}
return 0;
}