blob: 4306a8ac4c5255e21fcffb9f20f7c8c610c8d129 [file] [log] [blame]
Denys Vlasenko26de70e2009-02-13 10:26:31 +00001/* This test is not yet added to Makefile */
2
3#include <stddef.h>
4#include <unistd.h>
5#include <signal.h>
6
7#include <sys/types.h>
8#include <sys/socket.h>
9static const struct sockaddr sa;
10
11int main(int argc, char **argv)
12{
13 int loops;
14 int pid;
15 sigset_t set;
16
17 sigemptyset(&set);
18 sigaddset(&set, SIGCHLD);
19 sigprocmask(SIG_BLOCK, &set, NULL);
20
21 loops = 999;
22 if (argv[1])
23 loops = atoi(argv[1]);
24
25 while (--loops >= 0) {
26 pid = fork();
27 if (pid < 0) _exit(1);
28 if (!pid) {
29 /* child */
30 int child = getpid();
31
32 loops = 99;
33 while (--loops) {
34 pid = fork();
35 if (pid < 0) _exit(1);
36 if (!pid) {
37 /* grandchild: kill child */
38 kill(child, SIGKILL);
39 _exit(0);
40 }
41 /* Add various syscalls you want to test here.
42 * strace will decode them and suddenly find
43 * process disappearing.
44 * But leave at least one case "empty", so that
45 * "kill grandchild" happens quicker.
46 * This produces cases when strace can't even
47 * decode syscall number before process dies.
48 */
49 switch (loops & 1) {
50 case 0: /* empty */ break;
51 case 1: sendto(-1, "Hello cruel world", 17, 0, &sa, sizeof(sa)); break;
52 }
53 /* kill grandchild */
54 kill(pid, SIGKILL);
55 }
56 _exit(0);
57 }
58 /* parent */
59 wait(NULL);
60 }
61 return 0;
62}