Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
[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?

share|improve this question
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. –  David Schwartz Jan 14 at 10:35

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks. Based on your answer, I have find another answer that explains this in more detail: unix.stackexchange.com/questions/37508/… –  bobo Jan 14 at 10:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.