Добавил:
Fragga
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <unistd.h>
int main()
{
int f1,f2,status1,status2;
switch(f1=fork())
{
case -1:
printf("can not fork\n");
exit (1);
case 0:
/**/
printf("I am the child \nMy pid is %d\n\n",getpid());
switch(f2=fork())
{
case -1:
printf("can not fork \n");
exit (1);
case 0:
/**/
printf("I am the grand child\nMy pid is %d\n",getpid());
exit(1);
break;
default:
wait(&status2);
break;
}
default: wait(&status1);
printf( "exit value %d\n ",status1 >>8 );
printf("exit status %d\n ",status1 &0377);
exit(0);
return(0);
}