-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlotterytest.c
41 lines (40 loc) · 1.11 KB
/
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"
int main()
{
int pid1, pid2, pid3;
printf(1, "Run 1 CPU to get best results\n");
printf(1, "Get ticks status via Ctrl+P(procdump())\n");
if ((pid1 = fork()) > 0) {
if ((pid2 = fork()) > 0) {
if ((pid3 = fork()) > 0) {
struct pstat p;
getpinfo(&p);
for (int i = 0; i < NPROC; i++) {
if (p.inuse[i]) {
printf(1, "%d %d %d\n", p.tickets[i], p.pid[i], p.ticks[i]);
}
}
exit();
} else if (pid3 == 0) {
settickets(10);
printf(1, "child3\n");
while (1) {
}
exit();
}
} else if (pid2 == 0) {
settickets(20);
printf(1, "child2\n");
while (1) {
}
exit();
}
} else if (pid1 == 0) {
settickets(30);
printf(1, "child1\n");
while (1) {
}
exit();
}
}