#include"stdio.h" #include"unistd.h" #include"sys/types.h" #include"signal.h" #include"wait.h" void sigchld_handler(int sig) { pid_t pid; int status; for(;(pid=waitpid(-1,&status,WNOHANG))>0;) { printf("child %d died :%d ",pid,WEXITSTATUS(status)); printf("hi,parent process received SIHHLD signal successfully! "); } return; } void main() { //pid_t pc,pr; int pc=fork(); if(pc==0) { printf("子进程! "); sleep(1); printf("This is child process with pid of %d ", getpid()); //exit(1); } else if(pc>0) { signal(SIGCHLD,sigchld_handler); pause(); } else { printf("创建进程出错! "); exit(1); } }