-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroundRobinTest.c
54 lines (47 loc) · 1.45 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
#include "types.h"
#include "stat.h"
#include "user.h"
int main() {
changePolicy(0);
int children = 0;
int retime;
int rutime;
int stime;
for (int i = 0; i <10 ; i++) {
int pid = fork();
if ( pid == 0) {
for (int i = 0; i < 1000; i++) {
printf(1, "/%d/ : /%d/\n", getpid(), i);
}
sleep(2000);
exit();
}
else children= children +1;
}
int sumTurnaround = 0;
int sumWaiting = 0;
int sumBurst = 0;
for (int i = 0; i <10 ; i++) {
int pid = wait2(&retime, &rutime, &stime);
int waitingTime = stime;
int sleeping = retime;
int cpuBurst = rutime;
int turnAround = waitingTime + sleeping+cpuBurst;
sumTurnaround += turnAround;
sumWaiting += waitingTime;
sumBurst += cpuBurst;
printf(1, "pid: %d, ", pid);
printf(1, "turnaround time = %d, ", turnAround);
printf(1, "waiting time = %d, ", waitingTime);
printf(1, "sleeping time = %d, ", sleeping);
printf(1, "cpu burst = %d, ", cpuBurst);
printf(1,"\n");
}
int avgTurnaround = sumTurnaround / 10;
int avgWaiting = sumWaiting / 10;
int avgCBT = sumBurst / 10;
printf(1, "\naverage turnaround time: %d\n",avgTurnaround);
printf(1, "average waiting time: %d\n",avgWaiting);
printf(1, "average cpu burst time: %d\n",avgCBT);
exit();
}