UNIX下管道的疑问
在 K & 的 Unix 编程环境中P,上面写着
" 管道中的程序实际上是同时运行的,而不是一个接一个地运行。
这意味着管道中的程序可以是交互式的;”
程序如何同时运行?
例如:$ who | grep 玛丽 |厕所-l
grep mary 将如何执行直到 who 运行或 wc -l 将如何执行直到 it 知道以前程序的结果吗?
In The Unix Programming Environment by K & P, it is written that
" The programs in a pipeline actually run at the same time, not one after another.
This means that programs in a pipeline can be interactive;"
How can programs run at same time?
For ex: $ who | grep mary | wc -l
How grep mary will be executed until who is run or how wc -l will be executed until it
knows results of previous programs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
who
将输出一行数据,grep
将接收该stdout< /code>,然后
wc
将读取并计数who
可能还为grep
等每个程序 写出更多数据需要前一个的结果,但在它可以开始工作之前不需要所有结果,这就是为什么流水线是可行的。
who
will output a line of data, whichgrep
will then receivestdout
, whichwc
will then read and countwho
may also have been writing out more data forgrep
etcEach program needs the results of the previous one, but it doesn't need all of the results before it can start working, which is why pipelining is feasible.