#include"stdio.h" #include"sys/types.h" #include"unistd.h" #include"signal.h" void sigint_handler(int sig) { printf("recevied SIGINT signal successed! "); return; } void main() { int pid=fork(); if(pid==0) { printf("子进程pid: %d ", getpid()); sleep(2); printf("休眠后的pid:%d ",getpid()); sleep(2); printf("第二次休眠后的pid:%d ",getpid()); exit(1); } else if(pid>0) { signal(SIGCHLD, sigint_handler); pause(); } else if(pid<0) { printf("创建进程出错! "); exit(1); } }