[英]linux: why if you pipe ps to grep, grep filter is in process output ? How does pipe works?
With a typical command like ps aux |grep foobar
why grep foobar
process is in output?使用像
ps aux |grep foobar
这样的典型命令,为什么grep foobar
进程在输出中?
I was thinking that ps aux
output was passed to grep to filter the lines by the pattern in grep argument but at the time you execute ps aux
grep is still not executed (at least it's what I was supposing, I am wrong for sure), is executed later.我在想
ps aux
输出被传递给 grep 以通过 grep 参数中的模式过滤行,但是在您执行ps aux
grep 时仍然没有执行(至少这是我的假设,我肯定错了),稍后执行。
How does pipe works then?那么管道是如何工作的呢?
The reason is simple:原因很简单:
grep
process (as the pipe target).grep
进程(作为管道目标)。ps
, which finds grep
running .ps
,它发现grep
正在运行。ps
to the standard input of grep
.ps
的标准输出连接到grep
的标准输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.