-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlotteryTest.c
41 lines (38 loc) · 882 Bytes
/
lotteryTest.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
#include "types.h"
#include "user.h"
#include "date.h"
void spin(int tix) {
struct rtcdate end;
unsigned x = 0;
unsigned y = 0;
while (x < 100000) {
y = 0;
while (y < 10000) {
y++;
}
x++;
}
getTime(&end);
printf(0, "spin with %d tickets ended at %d hours %d minutes %d seconds\n", tix, end.hour, end.minute, end.second);
}
int main() {
int pid1;
int pid2;
struct rtcdate start;
getTime(&start);
printf(0, "starting test at %d hours %d minutes %d seconds\n", start.hour, start.minute, start.second);
if ((pid1 = fork()) == 0) {
setTickets(80);
spin(80);
exit();
}
else if ((pid2 = fork()) == 0) {
setTickets(1);
spin(1);
exit();
}
// Go to sleep and wait for subprocesses to finish
wait();
wait();
exit();
}