1 /* $OpenBSD: earlysig.c,v 1.2 2007/08/01 21:32:53 miod Exp $ */
2
3 /*
4 * Public domain. 2005, Otto Moerbeek
5 *
6 * Try to create the case where a signal is delivered to a process before
7 * fork() returns.
8 */
9
10 #include <sys/types.h>
11 #include <sys/wait.h>
12
13 #include <err.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <signal.h>
17 #include <unistd.h>
18
dohup(int signo)19 void dohup(int signo)
20 {
21 }
22
23 int
main()24 main()
25 {
26 pid_t pid;
27 int status;
28
29 signal(SIGHUP, dohup);
30
31 switch(pid = fork()) {
32 case -1:
33 err(1, "fork");
34 break;
35 case 0:
36 sleep(2);
37 exit(0);
38 default:
39 kill(pid, SIGHUP);
40 sleep(1);
41 if (waitpid(pid, &status, 0) == -1)
42 err(1, "waitpid");
43 if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
44 exit(0);
45 else
46 errx(1, "child exited with status %d",
47 WEXITSTATUS(status));
48 }
49 }
50