操作系统第五题
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/wait.h>
int main()
{
int child,p,p1,p2;
while((child=fork())==-1);
if(child==0)
{
execl("/home/fyb/fyb/welcome.out","",NULL);
}
else
{
while((p2=fork())==-1);
if(p2==0)
{
printf("In child :sleep for 10 second and then exit.\n");
sleep(10);
exit(0);
}
else
{
p1=waitpid(child,NULL,0);
if(p1==child)
{ printf("child1 over\n");
do{
p1=waitpid(p2,NULL,WNOHANG);
if(p==0)
{printf("IN father the child2 process has not exit! \n");
sleep(1);}
}while(p1==0);
if(p1==p2)
printf("GET child exitcode then exit!\n");
}
else printf("ERROR occured!\n");
}
printf("father over");
} exit(0); }
浙公网安备 33010602011771号