File tree 2 files changed +47
-1
lines changed
2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ PROGS=alarm \
14
14
signal-vs-sigaction \
15
15
sigsegv \
16
16
sigwait \
17
- sigpending
17
+ sigpending \
18
+ sigchld
18
19
19
20
all : $(PROGS )
20
21
@@ -72,6 +73,9 @@ sigwait: sigwait.o
72
73
sigpending : sigpending.o
73
74
$(CC ) -o $@ $^
74
75
76
+ sigchld : sigchld.o
77
+ $(CC ) -o $@ $^
78
+
75
79
clean :
76
80
rm -f * .o a.out $(PROGS )
77
81
Original file line number Diff line number Diff line change
1
+ /*
2
+ * The SIGCHLD signal is always delivered to the parent process except
3
+ * in case it is ignored.
4
+ */
5
+
6
+ #include <stdio.h>
7
+ #include <signal.h>
8
+ #include <unistd.h>
9
+ #include <sys/types.h>
10
+ #include <sys/wait.h>
11
+
12
+ void
13
+ handler (int s )
14
+ {
15
+ write (1 , "got it\n" , 7 );
16
+ }
17
+
18
+ int
19
+ main (int argc , char * argv [])
20
+ {
21
+ pid_t pid ;
22
+
23
+ #ifdef HANDLE_SIGCHLD
24
+ struct sigaction act ;
25
+ // act.sa_handler = handler;
26
+ act .sa_handler = SIG_IGN ;
27
+ sigemptyset (& act .sa_mask );
28
+ act .sa_flags = 0 ;
29
+ sigaction (SIGCHLD , & act , NULL );
30
+ #endif
31
+
32
+ if ((pid = fork ()) == 0 ) {
33
+ sleep (1 );
34
+ } else {
35
+ int status ;
36
+ printf ("forked %d\n" , pid );
37
+ // wait(&status);
38
+ waitpid (pid , & status , 0 );
39
+ }
40
+
41
+ return (0 );
42
+ }
You can’t perform that action at this time.
0 commit comments