From owner-freebsd-questions@FreeBSD.ORG Mon Dec 12 16:16:58 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 2E35616A420 for ; Mon, 12 Dec 2005 16:16:58 +0000 (GMT) (envelope-from xfb52@dial.pipex.com) Received: from smtp-out6.blueyonder.co.uk (smtp-out6.blueyonder.co.uk [195.188.213.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id BBE0043D60 for ; Mon, 12 Dec 2005 16:16:55 +0000 (GMT) (envelope-from xfb52@dial.pipex.com) Received: from [82.41.32.173] ([82.41.32.173]) by smtp-out6.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Mon, 12 Dec 2005 16:17:49 +0000 Message-ID: <439DA275.70404@dial.pipex.com> Date: Mon, 12 Dec 2005 16:16:53 +0000 From: Alex Zbyslaw User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-GB; rv:1.7.12) Gecko/20051106 X-Accept-Language: en MIME-Version: 1.0 To: Eric Schuele References: <439D9FA3.7030603@computer.org> In-Reply-To: <439D9FA3.7030603@computer.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 Dec 2005 16:17:49.0530 (UTC) FILETIME=[986A13A0:01C5FF37] Cc: FreeBSD Questions Subject: Re: grep'ping the ps output.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Dec 2005 16:16:58 -0000 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