1 #include <assert.h> 2 #include <signal.h> 3 #include <stdio.h> 4 #include <unistd.h> 5 #include <sys/wait.h> 6 handler(int signo)7void handler(int signo) { 8 printf("SIGCHLD\n"); 9 } 10 main()11int main() { 12 void *ret = signal(SIGINT, handler); 13 assert (ret != SIG_ERR); 14 15 pid_t child_pid = fork(); 16 assert (child_pid != -1); 17 18 if (child_pid == 0) { 19 sleep(1); 20 _exit(14); 21 } 22 23 printf("signo = %d\n", SIGCHLD); 24 printf("code = %d\n", CLD_EXITED); 25 printf("child_pid = %d\n", child_pid); 26 printf("uid = %d\n", getuid()); 27 pid_t waited = wait(NULL); 28 assert(waited == child_pid); 29 30 return 0; 31 } 32