[sf-lug] ps and grep

Kristian Erik Hermansen kristian.hermansen at gmail.com
Thu Mar 6 19:11:06 PST 2008

On Thu, Mar 6, 2008 at 5:17 PM, Tom Haddon <tom at greenleaftech.net> 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...

Use ps -e instead.  Here is an example to prove what is happening.
The second command needs to keep a pipe open for input from the first
command, so you know it interprets the post-pipe command first...

khermans at khermans-laptop:/tmp$ echo foo | time
Usage: time [-apvV] [-f format] [-o file] [--append] [--verbose]
       [--portability] [--format=format] [--output=file] [--version]
       [--quiet] [--help] command [arg...]
bash: echo: write error: Broken pipe
Kristian Erik Hermansen
"It has been just so in all my inventions. The first step is an
intuition--and comes with a burst, then difficulties arise. This thing
gives out and then that--'Bugs'--as such little faults and
difficulties are called--show themselves and months of anxious
watching, study and labor are requisite before commercial success--or
failure--is certainly reached" -- Thomas Edison in a letter to
Theodore Puskas on November 18, 1878

More information about the sf-lug mailing list