terminal - 在终端上管道重复输出
问题描述
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
为什么会发生这种情况
解决方案
推荐阅读
- javascript - 是否可以在运行时在 Node.js 中生成带有函数的对象?
- reactjs - 使用 componentDidUpdate 在反应中更新状态
- python - 使用线性回归的时间序列
- java - 休眠中事务中的延迟更新创建问题
- python - 将键多值字符串转换为键值对
- windows - 错误处理程序未捕获 PowerShell 中的错误
- javascript - 如何防止 ajax 表单提交写在任何地方?
- c# - 添加到列表返回 null
- javascript - 使用 querySelector 时的奇怪行为
- javascript - 使用 Bash heredoc 在 Bash 终端中运行 ES6 代码