Date: Mon, 12 Dec 2005 11:08:11 -0500 (EST) From: "Louis J. LeBlanc" <FreeBSD@keyslapper.net> To: "Eric Schuele" <e.schuele@computer.org> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: grep'ping the ps output.... Message-ID: <7002.38.112.155.126.1134403691.squirrel@www.keyslapper.net> In-Reply-To: <439D9FA3.7030603@computer.org> References: <439D9FA3.7030603@computer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, December 12, 2005 11:04 am, 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 presen= t > 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. > > Thanks, > Eric > > > %ps | grep firefox^M^M > 703 v0 I 0:00.00 /bin/sh /usr/X11R6/bin/firefox^M > 722 v0 I 0:00.00 /bin/sh /usr/X11R6/lib/firefox/run-mozilla.s= h > /usr/X1^ > M > 734 v0 S 0:10.92 /usr/X11R6/lib/firefox/firefox-bin^M > %ps | grep firefox^M^M > 703 v0 I 0:00.00 /bin/sh /usr/X11R6/bin/firefox^M > 722 v0 I 0:00.00 /bin/sh /usr/X11R6/lib/firefox/run-mozilla.s= h > /usr/X1^ > M > 734 v0 S 0:10.92 /usr/X11R6/lib/firefox/firefox-bin^M > 1230 p1 RV 0:00.00 grep firefox (csh)^M > <SNIP> You probably want something more like this: ps | grep firefox-bin | grep -v grep piping the first output set back into grep -v grep filters out any entry that matches the token "grep", pulling out the one you're trying to avoid= . HTH Lou --=20 Louis LeBlanc FreeBSD@keyslapper.net Fully Funded Hobbyist, KeySlapper Extrordinaire :=FE http://www.keyslapper.net =D4=BF=D4=AC
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7002.38.112.155.126.1134403691.squirrel>