1 /* 2 Test assertion #21 by verifying that adding a sigaction for SIGCHLD 3 with the SA_NOCLDWAIT bit set in sigaction.sa_flags will result in 4 a child process not transforming into a zombie after death. 5 */ 6 7 #define _XOPEN_SOURCE 600 8 9 #include <signal.h> 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <sys/wait.h> 13 #include <unistd.h> 14 #include <errno.h> 15 #include "posixtest.h" 16 17 void handler(int signo) 18 { 19 printf("Caught SIGCHLD\n"); 20 } 21 22 int main(void) 23 { 24 25 /* Make sure this flag is supported. */ 26 #ifndef SA_NOCLDWAIT 27 fprintf(stderr, "SA_NOCLWAIT flag is not available for testing\n"); 28 return PTS_UNSUPPORTED; 29 #endif 30 31 struct sigaction act; 32 33 act.sa_handler = handler; 34 act.sa_flags = SA_NOCLDWAIT; 35 sigemptyset(&act.sa_mask); 36 sigaction(SIGCHLD, &act, 0); 37 38 if (fork() == 0) { 39 /* child */ 40 return 0; 41 } else { 42 /* parent */ 43 int s; 44 if (wait(&s) == -1 && errno == ECHILD) { 45 printf("Test PASSED\n"); 46 return PTS_PASS; 47 } 48 } 49 50 printf("Test FAILED\n"); 51 return PTS_FAIL; 52 } 53