UNIX下管道的疑问

发布于 2024-08-28 23:31:25 字数 201 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2024-09-04 23:31:25
  • 所有三个程序都将启动。 grep 和 wc 等待通过标准输入输入
  • who 将输出一行数据,grep 将接收该
  • 行数据 如果该行匹配,grep 会将其写入 stdout< /code>,然后 wc 将读取并计数
  • 同时,who 可能还为 grep

每个程序 写出更多数据需要前一个的结果,但在它可以开始工作之前不需要所有结果,这就是为什么流水线是可行的。

  • All three programs will start. grep and wc wait for input via stdin
  • who will output a line of data, which grep will then receive
  • If the line matches, grep will write it to stdout, which wc will then read and count
  • In the meantime, who may also have been writing out more data for grep etc

Each 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文