#include<stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <wait.h>
void sighandler_t(int nu)
{
pid_t pid;
pid = wait(NULL);
printf("child process exit, pid:%x\n",pid);
}
int main()
{
pid_t pid;
signal(SIGCHLD, sighandler_t);
if((pid= fork())<0){
perror("fork err");
}else if(pid == 0){
printf("I am child1,myPid:%x\n",getpid());
sleep(1);
_exit(0);
}
if((pid= fork())<0){
perror("fork err");
}else if(pid == 0){
printf("I am child2,myPid:%x\n",getpid());
sleep(2);
_exit(0);
}
while(1){
printf("parent:%x\n",getpid());
sleep(2);
}
exit(0);
}