]>
Commit | Line | Data |
---|---|---|
964d3577 A |
1 | #include <errno.h> |
2 | #include <pthread.h> | |
3 | #include <stdio.h> | |
4 | #include <unistd.h> | |
5 | #include <os/assumes.h> | |
6 | #include <sys/wait.h> | |
7 | ||
8 | #define DECL_ATFORK(x) \ | |
9 | static void prepare_##x(void) { \ | |
10 | printf("%d: %s\n", getpid(), __FUNCTION__); \ | |
11 | } \ | |
12 | static void parent_##x(void) { \ | |
13 | printf("%d: %s\n", getpid(), __FUNCTION__); \ | |
14 | } \ | |
15 | static void child_##x(void) { \ | |
16 | printf("%d: %s\n", getpid(), __FUNCTION__); \ | |
17 | } | |
18 | ||
19 | #define ATFORK(x) \ | |
20 | os_assumes_zero(pthread_atfork(prepare_##x, parent_##x, child_##x)); | |
21 | ||
22 | DECL_ATFORK(1); | |
23 | DECL_ATFORK(2); | |
24 | DECL_ATFORK(3); | |
25 | DECL_ATFORK(4); | |
26 | DECL_ATFORK(5); | |
27 | DECL_ATFORK(6); | |
28 | DECL_ATFORK(7); | |
29 | DECL_ATFORK(8); | |
30 | DECL_ATFORK(9); | |
31 | DECL_ATFORK(10); | |
32 | DECL_ATFORK(11); | |
33 | DECL_ATFORK(12); | |
34 | DECL_ATFORK(13); | |
35 | DECL_ATFORK(14); | |
36 | DECL_ATFORK(15); | |
37 | DECL_ATFORK(16); | |
38 | DECL_ATFORK(17); | |
39 | DECL_ATFORK(18); | |
40 | DECL_ATFORK(19); | |
41 | ||
42 | int main(int argc, char *argv[]) { | |
43 | ATFORK(1); | |
44 | ATFORK(2); | |
45 | ATFORK(3); | |
46 | ATFORK(4); | |
47 | ATFORK(5); | |
48 | ATFORK(6); | |
49 | ATFORK(7); | |
50 | ATFORK(8); | |
51 | ATFORK(9); | |
52 | ATFORK(10); | |
53 | ATFORK(11); | |
54 | ATFORK(12); | |
55 | ATFORK(13); | |
56 | ATFORK(14); | |
57 | ATFORK(15); | |
58 | ATFORK(16); | |
59 | ATFORK(17); | |
60 | ATFORK(18); | |
61 | ATFORK(19); | |
62 | ||
63 | pid_t pid = fork(); | |
64 | if (pid == 0) { | |
65 | pid = fork(); | |
66 | } | |
67 | if (pid == -1) { | |
68 | posix_assumes_zero(pid); | |
69 | } else if (pid > 0) { | |
70 | int status; | |
71 | posix_assumes_zero(waitpid(pid, &status, 0)); | |
72 | posix_assumes_zero(WEXITSTATUS(status)); | |
73 | } | |
74 | return 0; | |
75 | } |