[root@myvm1 ~]# ps aux | grep ls
root 13594 0.0 0.1 3912 672 pts/1 R+ 09:46 0:00 grep ls
In the above, the ps aux
runs first and its output is then redirected to the grep ls
command. The grep ls
command runs after ps aux
.
So why can ps
know about the process that runs after it and has it in its output?
grep
can't process any output until after it's created, thegrep
process can be created either before or after theps
process. There's no special reason it has to be one way or the other.