*BSD News Article 91002


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!howland.erols.net!rill.news.pipex.net!pipex!warwick!lyra.csx.cam.ac.uk!news
From: Gareth McCaughan <gjm11@dpmms.cam.ac.uk>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: A shell oddity (bug?)
Date: 12 Mar 1997 14:43:39 +0000
Organization: International Pedant Conspiracy
Lines: 27
Message-ID: <86hgihrx0k.fsf@g.pet.cam.ac.uk>
References: <jpt2g5.q2c.ln@dolphin.neosoft.com>
NNTP-Posting-Host: g.pet.cam.ac.uk
X-Newsreader: Gnus v5.3/Emacs 19.34
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:37011

Conrad Sabatier wrote:
> ps -xU news | grep fetch
...
> However, sometimes the "grep fetch" itself also appears in the
> output!
> 
> This makes no sense to me.  Grep should be receiving the piped
> output of ps taken from *before* grep was running.

Er, why? The whole point of pipes is that the writing and reading
processes can be running at the same time. When you do
  ps -blah | grep foo
the shell forks off two copies of itself, which splice their input
and output together in the right way; then the first one runs "ps"
and the second one runs "grep".

One trick you can use if this bothers you is:

  ps -auxww | grep [d]oom

which will look for things containing "doom" just as if you'd done
"grep doom", but since "doom" doesn't appear in the invocation of
grep that won't show up. :-)

-- 
Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
gjm11@dpmms.cam.ac.uk  Cambridge University, England.