[sf-lug] ps and grep

jim stockford jim at well.com
Thu Mar 6 17:47:07 PST 2008



at the point you type the  ps  command and hit
enter, you've kicked off a new process, something
like
$ ps aux | grep doit

the pipe character is also a command delimiter:
you've kicked off two processes, the first one loaded
is the  grep  process and the second one loaded is
the  ps  process. after all, nothing runs unless it's a
process, and for  ps  to get the output of  grep  then
grep has to be loaded first so's to be in place, right?

but it's only after those two processes are loaded
that the  ps  command starts its work, which means
it's dumping all processes including the  grep
process and the  ps  process itself. you've asked
grep to filter out everything but any line that has
doit on it, so if the doit process is running, you get
that line, and you also get the line for which doit is
an argument: the grep process.

make sense?



On Mar 6, 2008, at 5:17 PM, Tom Haddon wrote:

> Bit of an elementary question, this, but can someone remind me why:
>
> ps fuwxx | grep <something>
>
> returns "grep <something>" in the list if finds? Intuition would 
> suggest
> that the ps is happening first, and so the grep command wouldn't show 
> in
> the list. One of those things that was explained to me once, but seems
> to have slipped through my sieve-like memory...
>
> Cheers, Tom
>
>
>
> _______________________________________________
> sf-lug mailing list
> sf-lug at linuxmafia.com
> http://linuxmafia.com/mailman/listinfo/sf-lug
>





More information about the sf-lug mailing list