#include<stdio.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t pid1;
pid_t pid2;
int pr1;
int pr2;
if((pid1=fork()) == -1 )
printf("pid1 Error!\n");
else if( pid1 == 0 )
{
execlp("ls","ls","-l",NULL);
}
else
{
pr1=wait(NULL);
printf("pr1 = %d, pid1 has exited!\n", pr1);
if((pid2=fork()) == -1 )
printf("pid2 Error!\n");
else if( pid2 == 0 )
{
sleep(5);
exit(1);
}
else
{
do
{
pr2 = waitpid(pid2,NULL,WNOHANG);
if( pr2 == pid2 )
printf("pr2 = %d, pid2 has exited!\n", pr2);
sleep(1);
}while(pr2 == 0 );
}
}
return 0;
}
test
最新推荐文章于 2023-05-23 21:58:23 发布