Issue
With a typical command like ps aux |grep foobar
why grep foobar
process is in output?
I was thinking thatps 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.
How does pipe works then?
Solution
The reason is simple:
- OS starts the
grep
process (as the pipe target). - OS starts the
ps
, which findsgrep
running. - OS connects the standard output of
ps
to the standard input ofgrep
.
Answered By - Antonio Petricca Answer Checked By - Gilberto Lyons (WPSolving Admin)