简体   繁体   English

如何在 C 中使用 fork() 制作倾斜树?

[英]How do I make a skewed tree using fork() in C?

I am looking to create a skewed tree with 3 nodes, 2 of which will have 1 child and the last node will be childless.我希望创建一个具有 3 个节点的倾斜树,其中 2 个节点将有 1 个子节点,最后一个节点将是无子节点。 I do not really understand how to proceed with this.我真的不明白如何进行此操作。

Example例子

This seems like the normal use of fork() , basically.基本上,这似乎是fork()的正常使用。 Here's some pseudocode:这是一些伪代码:

// start in process 3
int pid = fork();
if (pid == 0) {
   int pid2 = fork();
   if (pid2 == 0) {
       // process 1
   } else {
       // process 2
   }
} else {
   // process 3
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM