#include #include #include #include static void ignore_sigchld(int signum) { return; } int main(int argc, char **argv) { struct sigaction sa; pid_t pid; sa.sa_handler = ignore_sigchld; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; if ( sigaction( SIGCHLD, &sa, NULL ) < 0 ) { perror( "sigaction" ); exit( 1 ); } if ( ( pid = fork() ) < 0 ) { perror( "fork" ); exit( 1 ); } if ( pid == 0 ) { sleep( 60 ); exit( 0 ); } if ( kill( pid, SIGKILL ) < 0 ) { perror( "kill" ); exit( 1 ); } else { pid_t caught; int status; while ( ( caught = waitpid( pid, &status, 0 ) ) < 0 ) { if ( errno != EINTR ) { perror( "waitpid" ); exit( 1 ); } } printf( "Child %d exited with status %d\n", caught, status ); } exit( 0 ); }