Date: Mon, 12 Dec 2005 16:16:53 +0000 From: Alex Zbyslaw <xfb52@dial.pipex.com> To: Eric Schuele <e.schuele@computer.org> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: grep'ping the ps output.... Message-ID: <439DA275.70404@dial.pipex.com> In-Reply-To: <439D9FA3.7030603@computer.org> References: <439D9FA3.7030603@computer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Eric Schuele wrote: > Hello, > > I am sure this is quite trivial, but... > > I have need to determine if an app (firefox, or anything really) is > already running before I perform some action. So I grep the ps > output. However sometimes (many times) that which I'm searching for > is present in the output because I am presently grep'ing for it. But > it is not always there. It seems to be a bit inconsistent. (See below). > > I was wondering if someone could explain why it is sometimes there and > not other times. And how I should correctly go about detecting if the > process is running before I perform my action. > ps | egrep firefox | egrep -v egrep I can't explain exactly why. It's clearly a timing thing. I guess if the ps runs quickly enough then perhaps the grep hasn't actually been started by the shell. Or if ps iterates over something, then maybe the grep appears in a part of the list that has already been looked at by ps. --Alex
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?439DA275.70404>