- #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\n",pid,WEXITSTATUS(status));
- printf("hi,parent process received SIHHLD signal successfully!\n");
- }
- return;
- }
- void main()
- {
- //pid_t pc,pr;
- int pc=fork();
- if(pc==0)
- {
- printf("子进程!\n");
- sleep(1);
- printf("This is child process with pid of %d\n", getpid());
- //exit(1);
- }
- else if(pc>0)
- {
- signal(SIGCHLD,sigchld_handler);
- pause();
- }
- else
- {
- printf("创建进程出错!\n");
- exit(1);
- }
- }
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702521