1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > linux进程家族树 linux下用c语言创建进程树

linux进程家族树 linux下用c语言创建进程树

时间:2019-12-23 22:48:42

相关推荐

linux进程家族树 linux下用c语言创建进程树

满意答案

wym_56

.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分享举报

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。