From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 2 20:45:53 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AD0CA10657A7 for ; Wed, 2 Nov 2011 20:45:53 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email2.allantgroup.com (email2.emsphone.com [199.67.51.116]) by mx1.freebsd.org (Postfix) with ESMTP id 711BE8FC18 for ; Wed, 2 Nov 2011 20:45:53 +0000 (UTC) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email2.allantgroup.com (8.14.4/8.14.4) with ESMTP id pA2Kjqh5075348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 2 Nov 2011 15:45:52 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.5/8.14.5) with ESMTP id pA2KjqhZ020471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 2 Nov 2011 15:45:52 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.5/8.14.5/Submit) id pA2Kjq9l020469; Wed, 2 Nov 2011 15:45:52 -0500 (CDT) (envelope-from dan) Date: Wed, 2 Nov 2011 15:45:51 -0500 From: Dan Nelson To: Mark Saad Message-ID: <20111102204551.GU93709@dan.emsphone.com> References: <20111102204002.GT93709@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20111102204002.GT93709@dan.emsphone.com> X-OS: FreeBSD 8.2-STABLE User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: clamav-milter 0.97.2 at email2.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.6 (email2.allantgroup.com [199.67.51.78]); Wed, 02 Nov 2011 15:45:52 -0500 (CDT) X-Scanned-By: MIMEDefang 2.68 on 199.67.51.78 Cc: freebsd-hackers@freebsd.org Subject: Re: What is going on with ash / sh X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Nov 2011 20:45:53 -0000 In the last episode (Nov 02), Dan Nelson said: > In the last episode (Nov 02), Mark Saad said: > > Hackers > > What is going on here, if I run the following shell script, what is > > the expected output . The script is named xxx > > > > #!/bin/sh > > ps -ax | grep -v grep | grep xxx > > > > Here is what I see > > > > # sh xxx > > 88318 p0 S+ 0:00.00 sh xxx > > 88320 p0 R+ 0:00.00 sh xxx > > 88321 p0 R+ 0:00.00 sh xxx > > > > Can someone explain this ? > > What does your script do? If it contains subshells or pipelines, the main > process will fork child processes to handle those. Sorry; I misread your original post. Yes, that script forks off two subshells to handle the pipeline, and the ps command caught the state where the subshells had been created but had not yet exec'ed their grep commands. -- Dan Nelson dnelson@allantgroup.com