why does ps |grep sometimes not return itself?

Jonathan McKeown j.mckeown at ru.ac.za
Thu Jun 10 07:45:48 UTC 2010


On Thursday 10 June 2010 03:30:14 Pieter de Goeje wrote:
> On Wednesday 09 June 2010 09:34:40 Matthew Seaman wrote:
> > On 09/06/2010 08:15:23, Eitan Adler wrote:
> > > Why do I sometimes see the grep in ps's output and sometimes not see
> > > it?
> >
> > When you run that pipeline the OS doesn't start both programs exactly
> > simultaneously. [...]  It's a race condition.
>
> I would like to add that you can avoid the issue entirely by using this
> command:
> % ps aux -p `pgrep sh`
[output snipped due to bad wrapping]

Or the old trick:

ps | grep '[s]h'

Jonathan


More information about the freebsd-questions mailing list