大佬教程收集整理的这篇文章主要介绍了控制C中的前叉,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main () { pid_t child_pid; printf ("The PID is %d\n",(int) getpid ()); child_pid = fork (); if (child_pid != 0) { printf ("this is the parent process,with PID %d\n",(int)getpid()); printf ("the child's PID is %d\n",(int) child_pid); } else printf ("this is the child process,(int)getpid()); return 0; }
parent (0) | +---> child (1) | +---> child (2) | +----> child (3) | +----> child (4) | +----> child (5) |
基本上是一个树形结构,每个第二个孩子生两个新孩子.据我所知,当我fork()一个进程时,每个进程将同时运行.在if语句中添加fork()似乎正常工作并正确创建进程0到2,因为只有父进程才会创建新的fork.但我不知道如何制作进程2 fork而不是1.任何想法?
以上是大佬教程为你收集整理的控制C中的前叉全部内容,希望文章能够帮你解决控制C中的前叉所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。