From owner-freebsd-questions@FreeBSD.ORG Thu Jun 10 01:30:26 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 25F6C1065673; Thu, 10 Jun 2010 01:30:26 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from mx.utwente.nl (mx3.utsp.utwente.nl [130.89.2.14]) by mx1.freebsd.org (Postfix) with ESMTP id 962388FC1C; Thu, 10 Jun 2010 01:30:25 +0000 (UTC) Received: from nox-laptop.student.utwente.nl (nox-laptop.student.utwente.nl [130.89.160.140]) by mx.utwente.nl (8.12.10/SuSE Linux 0.7) with ESMTP id o5A1UEM9021805; Thu, 10 Jun 2010 03:30:14 +0200 From: Pieter de Goeje To: freebsd-questions@freebsd.org Date: Thu, 10 Jun 2010 03:30:14 +0200 User-Agent: KMail/1.9.10 References: <4C0F4410.40900@infracaninophile.co.uk> In-Reply-To: <4C0F4410.40900@infracaninophile.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201006100330.14618.pieter@degoeje.nl> X-UTwente-MailScanner-Information: Scanned by MailScanner. Contact icts.servicedesk@utwente.nl for more information. X-UTwente-MailScanner: Found to be clean X-UTwente-MailScanner-From: pieter@degoeje.nl X-Spam-Status: No Cc: Eitan Adler , questions@freebsd.org Subject: Re: why does ps |grep sometimes not return itself? 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: Thu, 10 Jun 2010 01:30:26 -0000 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? > > [eitan@AlphaBeta ~ ]% ps aux|grep Me > > eitan 96325 0.0 0.0 1856 724 5 RL+ 10:14AM 0:00.00 grep Me > > [eitan@AlphaBeta ~ ]% ps aux|grep Me > > [eitan@AlphaBeta ~ !1! ]% > > When you run that pipeline the OS doesn't start both programs exactly > simultaneously. It starts ps(1) first, then grep(1) together with > creating the pipeline by connecting ps's stdout to grep's stdin. > Depending on system load and various other factors, this may allow ps(1) > to grab the snapshot of the process table that it works on before > grep(1) has started. It's a race condition. > > Whether you see this effect or not will depend very much on system > conformation and load. I can't reproduce the effect on a lightly loaded > dual processor machine, which always shows the grep process, whereas on > a single processor virtual machine running under VirtualBox, I never see > grep in the ps output unless I renice the ps(1) process. > I would like to add that you can avoid the issue entirely by using this command: % ps aux -p `pgrep sh` USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND root 1326 0.0 0.1 6680 3664 ?? Is 1:09AM 0:00.00 /usr/sbin/sshd pyotr 1460 0.0 0.1 3972 2696 v0 I 1:09AM 0:00.02 -zsh (zsh) -- Pieter de Goeje