操作系统第五题

#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); }

posted @ 2023-03-26 21:58  宠柳娇花  阅读(15)  评论(0)    收藏  举报