2
[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?

1
  • 2
    While grep can't process any output until after it's created, the grep process can be created either before or after the ps process. There's no special reason it has to be one way or the other. Jan 14, 2014 at 10:35

1 Answer 1

4

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?

You are writing about a logical order of command sequencing.

If you get insights in bash proceedings you get to know that both commands and the piping framework may be created in an order that does not really matter.

Moreover the piping framework is most probably a command output redirection.

Your answer is: the command ps is run actually after the process that will run grep has been created.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .