#include<stdio.h>#include<stdlib.h>#include <sys/types.h>#include <sys/wait.h>#include<signal.h>int main()
{
pid_t pid = 0;
pid = fork();
int status;
if(pid < 0)
{
perror("fork error....\n");
return -1;
}
if(pid == 0)
{
int i = 0;
pid_t pid = 0;
for(i = 0; i < 5; i++)
{
pid = fork();
if(pid == 0)
{
printf("son pid is %d\n",getpid());
_exit(5);
}
}
//sleep(5);
printf("son pid is,,,,,,, %d\n",getpid());
//_exit(5);
}elseif(pid > 0)
{
int ret = 0;
sleep(1);
//kill(pid,SIGQUIT);
printf("father begin to wait....\n");
wait(&status);// there are six son,but wait can deal one son
if((ret = WIFEXITED(status)) != 1)//is normal exit,such as exit,returnand _exit
{
if((ret = WIFSIGNALED(status))!=0)//is terminal by a signal??
printf("terminal by signal\n");
}else{
ret = WEXITSTATUS(status);//return value of exitprintf("exit is %d\n",ret);
}
}
printf("fathre is break....\n");
while(1);
}