-
Notifications
You must be signed in to change notification settings - Fork 2
/
p-testeintr.cc
47 lines (38 loc) · 1.11 KB
/
p-testeintr.cc
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
#include "p-lib.hh"
static const int order[] = {
2, 7, 6, 4, 1, 8, 5, 3
};
static void make_children(pid_t* children) {
for (size_t i = 0; i != arraysize(order); ++i) {
pid_t p = sys_fork();
if (p == 0) {
sys_msleep(order[i] * 500);
sys_exit(order[i]);
}
children[i] = p;
}
}
void process_main() {
sys_kdisplay(KDISPLAY_NONE);
pid_t children[arraysize(order)];
make_children(children);
for (size_t i = 0; i != arraysize(order); ++i) {
int r = sys_msleep(1000);
assert_eq(r, E_INTR);
int status = 0;
pid_t ch = sys_waitpid(0, &status, W_NOHANG);
assert_gt(ch, 0);
size_t idx = 0;
while (idx != arraysize(order) && children[idx] != ch) {
++idx;
}
assert(idx < arraysize(order));
children[idx] = 0;
console_printf("%d @%lu: exit status %d\n", ch, idx, status);
assert_eq(order[idx], status);
}
assert_eq(sys_waitpid(0), E_CHILD);
assert_eq(sys_msleep(1000), 0);
console_printf("testeintr succeeded.\n");
sys_exit(0);
}