的代码看起来是这样的fork()调用打印更多的时间比预期的
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
printf("Starting process id is %d\t", getpid());
if (fork() == 0)
fork();
else {
fork();
fork();
exit(0);
}
printf("%d\t", getpid());
}
对于输出像预期的那样在那里追踪的大部分。也就是说,如果我们开始与ID n
我们得到被打印n+1
和n+5
。但是,当我打印启动进程ID它打印5次,我不知道为什么。任何帮助,将不胜感激
输出看起来像这样
开始的进程ID是27252 PC @ PC-VirtualBox的:〜/桌面$ 开始porcess ID是27252起porcess ID是27252启动 porcess ID是27252 27253起porcess ID是27252起 进程ID是27252 27257
不过我本来期望看到
凝望进程ID是27252 27253 27257
你什么输出,以及你期望什么样的产出? – aschepler
叉/行缓冲多重复数据删除:( –