满意答案
wym_56
2013.08.18
采纳率:57% 等级:12
已帮助:9119人
有问题Q我吧,QQ: 402892954
#include
#include
int main(void) {
int p,p11,p12,p13,p21,p22;
while ((p=fork())==-1);
if (!p) {
printf("Parent with pid %d, parent pid %d.\n",getpid(),getppid());
while ((p11=fork())==-1);
if (!p11) {
printf("child11 with pid %d, parent pid %d.\n",getpid(),getppid());
while ((p21=fork())==-1);
if (!p21) {
printf("child21 with pid %d, parent pid %d.\n",getpid(),getppid());
exit(0);
}
else
wait(0);
while ((p22=fork())==-1);
if (!p22) {
printf("child22 with pid %d, parent pid %d.\n",getpid(),getppid());
exit(0);
}
else
wait(0);
exit(0);
}
else
wait(0);
while ((p12=fork())==-1);
if (!p12) {
printf("child12 with pid %d, parent pid %d.\n",getpid(),getppid());
exit(0);
}
else
wait(0);
while ((p13=fork())==-1);
if (!p13) {
printf("child13 with pid %d, parent pid %d.\n",getpid(),getppid());
exit(0);
}
else
wait(0);
exit(0);
}
else
wait(0);
return 0;
}
00分享举报