-
Notifications
You must be signed in to change notification settings - Fork 2
/
roundRobinTest.c
82 lines (61 loc) · 1.6 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "types.h"
#include "stat.h"
#include "user.h"
Times *times;
void
averageCBT(Times *times)
{
int result = 0;
for (int i = 0; i < 10; i++){
result += times[i].runningTime;
printf(1, "the CBT for process %d is: %d\n", i, times[i].runningTime);
}
result /= 10;
printf(1, "the average CBT is: %d\n", result);
}
void
averageTurnaroundTime(Times *times)
{
int result = 0;
for (int i = 0; i < 10; i++){
result += times[i].runningTime + times[i].sleepingTime + times[i].readyTime;
printf(1, "the turnAroundTime for process %d is: %d\n", i, times[i].runningTime + times[i].sleepingTime + times[i].readyTime);
}
result /= 10;
printf(1, "the average turnArounTime is: %d\n", result);
}
void
averageWaitingTime(Times *times)
{
int result = 0;
for (int i = 0; i < 10; i++){
result += times[i].sleepingTime + times[i].readyTime;
printf(1, "the waitingTime for process %d is: %d\n", i, times[i].sleepingTime + times[i].readyTime);
}
result /= 10;
printf(1, "the average WaitingTime is: %d\n", result);
}
int
main()
{
times = (Times *) malloc(10 * sizeof(Times));
changePolicy(3);
int i, j, k;
for (i = 0; i < 10; i++)
{
if (fork() == 0)
{
for (j = 1; j < 1000; j++)
printf(1, "%d : %d\n", getpid(), j);
exit();
}
}
for (k = 0; k < 10; k++){
wait2(×[k]);
}
averageCBT(times);
averageTurnaroundTime(times);
averageWaitingTime(times);
exit();
return 1;
}