forked from PriyansuBisht/Operating-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_RoundRobin_Algo.c
53 lines (48 loc) · 1.6 KB
/
06_RoundRobin_Algo.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
#include <stdio.h>
int main() {
int i, NOP, sum = 0, count = 0, y, quant, wt = 0, tat = 0, at[10], bt[10], temp[10];
float avg_wt, avg_tat;
printf("Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP;
for (i = 0; i < NOP; i++) {
printf("\nEnter the Arrival and Burst time of the Process[%d]", i + 1);
printf("\n\nArrival time is: ");
scanf("%d", &at[i]);
printf("Burst time is: ");
scanf("%d", &bt[i]);
temp[i] = bt[i];
}
printf("\nEnter the Time Quantum for the process: ");
scanf("%d", &quant);
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for (sum = 0, i = 0; y != 0;) {
if (temp[i] <= quant && temp[i] > 0) {
sum = sum + temp[i];
temp[i] = 0;
count = 1;
} else if (temp[i] > 0) {
temp[i] = temp[i] - quant;
sum = sum + quant;
}
if (temp[i] == 0 && count == 1) {
y--;
printf("\nProcess No[%d] \t\t %d\t\t\t\t %d\t\t\t %d", i + 1, bt[i], sum - at[i], sum - at[i] - bt[i]);
wt = wt + sum - at[i] - bt[i];
tat = tat + sum - at[i];
count = 0;
}
if (i == NOP - 1) {
i = 0;
} else if (at[i + 1] <= sum) {
i++;
} else {
i = 0;
}
}
avg_wt = wt * 1.0 / NOP;
avg_tat = tat * 1.0 / NOP;
printf("\n Average Turn Around Time: %.3f", avg_wt);
printf("\n Average Waiting Time: %.3f", avg_tat);
return 0;
}