From owner-freebsd-questions@FreeBSD.ORG Mon Dec 12 16:12:44 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E8BFA16A420 for ; Mon, 12 Dec 2005 16:12:44 +0000 (GMT) (envelope-from FreeBSD@keyslapper.net) Received: from russian-caravan.cloud9.net (russian-caravan.cloud9.net [168.100.1.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 332EA43D80 for ; Mon, 12 Dec 2005 16:12:33 +0000 (GMT) (envelope-from FreeBSD@keyslapper.net) Received: from russian-caravan.cloud9.net (localhost [127.0.0.1]) by russian-caravan.cloud9.net (Postfix) with SMTP id AAC4D17691; Mon, 12 Dec 2005 11:12:25 -0500 (EST) Received: from keyslapper.net (250-119.customer.cloud9.net [168.100.250.119]) by russian-caravan.cloud9.net (Postfix) with ESMTP id A784917758; Mon, 12 Dec 2005 11:12:21 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by keyslapper.net (Postfix) with ESMTP id 989231178E; Mon, 12 Dec 2005 11:08:11 -0500 (EST) Received: from keyslapper.net ([127.0.0.1]) by localhost (keyslapper.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 78980-07; Mon, 12 Dec 2005 11:08:11 -0500 (EST) Received: from www.keyslapper.net (localhost [127.0.0.1]) by keyslapper.net (Postfix) with ESMTP id 4B4221144A; Mon, 12 Dec 2005 11:08:11 -0500 (EST) Received: from 38.112.155.126 (SquirrelMail authenticated user leblanc) by www.keyslapper.net with HTTP; Mon, 12 Dec 2005 11:08:11 -0500 (EST) Message-ID: <7002.38.112.155.126.1134403691.squirrel@www.keyslapper.net> In-Reply-To: <439D9FA3.7030603@computer.org> References: <439D9FA3.7030603@computer.org> Date: Mon, 12 Dec 2005 11:08:11 -0500 (EST) From: "Louis J. LeBlanc" To: "Eric Schuele" User-Agent: SquirrelMail/1.4.5 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: amavisd-new at keyslapper.net Content-Transfer-Encoding: quoted-printable X-AntiVirus: Checked by Vexira Antivirus v1.5 Cc: FreeBSD Questions Subject: Re: grep'ping the ps output.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@FreeBSD.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Dec 2005 16:12:45 -0000 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 > 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