-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroundRobinTest.c
66 lines (56 loc) · 1.63 KB
/
roundRobinTest.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
#include "types.h"
#include "stat.h"
#include "user.h"
struct timing
{
uint creationTime;
uint terminationTime;
uint runningTime;
uint readyTime;
uint sleepingTime;
};
int main(void)
{
changePolicy(1); // 1 stands for RR
int i = 0;
int j = 0;
int k = 0;
struct timing times[10];
for (j = 0; j < 10; j++)
{
if (fork() == 0) // child process
{
for (i = 1; i < 1000; i++)
{
printf(1, "[%d]: [%d] \n", getpid(), i);
}
exit();
}
}
for (k = 0; k < 10; k++)
waitWithTimings(×[k]);
int sumTurnaroundTime = 0;
int sumCBT = 0;
int sumWaitingTime = 0;
for (k = 0; k < 10; k++)
{
printf(1, "Child number : %d \n", (k + 1));
printf(1, "Turnaround time : %d \n", (times[k].terminationTime - times[k].creationTime));
printf(1, "CBT : %d \n", times[k].runningTime);
printf(1, "Waiting time : %d \n", times[k].readyTime);
printf(1, "\n");
sumTurnaroundTime += (times[k].terminationTime - times[k].creationTime);
sumCBT += times[k].runningTime;
sumWaitingTime += times[k].readyTime;
}
// calculating parameters
int childNumber = 10;
int avgTurnaroundTime = sumTurnaroundTime / childNumber;
int avgCBT = sumCBT / childNumber;
int avgWaitingTime = sumWaitingTime / childNumber;
printf(1, "All Processes : \n");
printf(1, "Average Turnaround time : %d \n", avgTurnaroundTime);
printf(1, "Average CBT : %d \n", avgCBT);
printf(1, "Average Waiting time : %d \n", avgWaitingTime);
exit();
}