-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.c
More file actions
39 lines (33 loc) · 832 Bytes
/
Copy pathtest1.c
File metadata and controls
39 lines (33 loc) · 832 Bytes
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
#include "apue.h"
int
main(void)
{
pid_t pid;
if ((pid = fork()) < 0)
err_sys("fork error");
else if (pid != 0) { /* parent */
sleep(2);
exit(2); /* terminate with exit status 2 */
}
if ((pid = fork()) < 0)
err_sys("fork error");
else if (pid != 0) { /* first child */
sleep(4);
abort(); /* terminate with core dump */
}
if ((pid = fork()) < 0)
err_sys("fork error");
else if (pid != 0) { /* second child */
execl("/bin/dd", "dd", "if=/etc/passwd", "of=/dev/null", NULL);
exit(7); /* shouldn't get here */
}
if ((pid = fork()) < 0)
err_sys("fork error");
else if (pid != 0) { /* third child */
sleep(8);
exit(0); /* normal exit */
}
sleep(6); /* fourth child */
kill(getpid(), SIGKILL); /* terminate w/signal, no core dump */
exit(6); /* shouldn't get here */
}