-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathp3.c
More file actions
55 lines (46 loc) · 1.24 KB
/
p3.c
File metadata and controls
55 lines (46 loc) · 1.24 KB
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
55
#include <signal.h>
#include <sys/wait.h>
#include "apue.h"
void pr_exit_2(siginfo_t *infop) {
if (siginfo->si_code == CLD_EXITED) {
printf("normal termination, exit status = %d\n", siginfo->si_status);
} else if (siginfo->si_code==CLD_KILLED || siginfo->si_code==CLD_DUMPED) {
printf("abnormal termination, signal number = %d%s\n", siginfo->si_status,
siginfo->si_code == CLD_DUMPED ? "(core file generated)" : "");
} else if (siginfo->si_code == CLD_STOPPED) {
printf("child stopped, signal number = %d\n", siginfo->si_status);
}
}
int main() {
pid_t pid;
int status;
siginfo_t infop;
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) {
exit(7);
}
if (waitid(P_ALL, 0, &infop, WEXITED) != 0) {
err_sys("waitid error");
}
pr_exit_2(&infop);
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) {
abort();
}
if (waitid(P_ALL, 0, &infop, WEXITED) != 0) {
err_sys("waitid error");
}
pr_exit_2(&infop);
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) {
status /= 0;
}
if (waitid(P_ALL, 0, &infop, WEXITED) != 0) {
err_sys("waitid error");
}
pr_exit_2(&infop);
exit(0);
}