如何在 C 中使用 fork() 创建倾斜树?
How do I make a skewed tree using fork() in C?
我想创建一个有 3 个节点的倾斜树,其中 2 个节点有 1 个子节点,最后一个节点没有子节点。我真的不明白如何进行。
Example
这似乎是 fork()
的正常使用,基本上。这是一些伪代码:
// start in process 3
int pid = fork();
if (pid == 0) {
int pid2 = fork();
if (pid2 == 0) {
// process 1
} else {
// process 2
}
} else {
// process 3
}
我想创建一个有 3 个节点的倾斜树,其中 2 个节点有 1 个子节点,最后一个节点没有子节点。我真的不明白如何进行。
Example
这似乎是 fork()
的正常使用,基本上。这是一些伪代码:
// start in process 3
int pid = fork();
if (pid == 0) {
int pid2 = fork();
if (pid2 == 0) {
// process 1
} else {
// process 2
}
} else {
// process 3
}