首页 > 解决方案 > 在终端上管道重复输出

问题描述

hellofork.c ∗​ ​ :
/*​ * Simple Hello world program with 2
processes.
*/ #include <stdio.h>
main() {​ printf("\%d:
Hello\n", getpid());
if (
!fork() )
printf("\%d: world\n", getpid()); 
}​

如果我们向程序中添加更多管道(一次按顺序观看一个屏幕的过滤器),则输出为:

terminal~> ./hellofork |
more terminal~> 53438:
Hello terminal~> 53438:
Hello terminal~> 53440:
world

为什么会发生这种情况

标签: terminalprocesspipeipcstdout

解决方案


推荐阅读