From owner-freebsd-ports@FreeBSD.ORG Fri Jun 1 15:07:27 2012 Return-Path: Delivered-To: freebsd-ports@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CD4D4106567B for ; Fri, 1 Jun 2012 15:07:27 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id 8C7428FC12 for ; Fri, 1 Jun 2012 15:07:27 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id D5F9D1DD63C; Fri, 1 Jun 2012 17:07:26 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id B3EBB2848C; Fri, 1 Jun 2012 17:07:26 +0200 (CEST) Date: Fri, 1 Jun 2012 17:07:26 +0200 From: Jilles Tjoelker To: Lars Engels Message-ID: <20120601150726.GA38814@stack.nl> References: <4E946838-4F3B-421A-839E-05E1A01464AB@FreeBSD.org> <20120601035349.GA97671@DataIX.net> <4FC8555E.3090802@rsu.ru> <20120601074308.GC39168@e-new.0x20.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120601074308.GC39168@e-new.0x20.net> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-ports@FreeBSD.org, Alexander Pyhalov Subject: Re: [ GSOC ] Differences in shell behaviour X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jun 2012 15:07:27 -0000 On Fri, Jun 01, 2012 at 09:43:08AM +0200, Lars Engels wrote: > On Fri, Jun 01, 2012 at 09:38:38AM +0400, Alexander Pyhalov wrote: > > Good morning. > > On 06/01/2012 07:53, Jason Hellenthal wrote: > > > On Thu, May 31, 2012 at 11:21:10PM +0400, Alexander Pronin wrote: > > >> The problem is: > > >> ### sh in 8.3 > > >> $ false& pid=$! > > >> $ > > >> [1] Done (1) false > > >> $ wait ${pid} > > >> wait: No such job: 4852 > > > I don't see this behavior on 8.3-STABLE @r236350 i386 > > > --- > > > Console> false& pid=$! > > > Console> wait ${pid} > > > [1] Done (1) false > > > Console> echo $? > > > 1 > > It seems to behave differently, when you issue some additional commands > > or interact with shell. > > first case (8.3 r234443): > > $ false &pid=$! > > $ wait ${pid} > > [1] Done (1) false > > $ echo $? > > 1 > > second case (8.3 r234443): > > $ false & pid=$! > > $ # some interaction with shell > > [1] Done (1) false > > $ wait ${pid} > > wait: No such job: 59092 > > Now, on 9.0-RELEASE > > first case: > > $ false & pid=$! > > $ wait ${pid} > > [1] Done(1) false > > $ echo $? > > 1 > > second case: > > $ false & pid=$! > > $ # some activity > > [1] Done(1) false > > $ wait ${pid} > > $ echo $? > > 1 > > Do you see the difference ? Which behavior is correct? Can it be a sh bug? > Adding jilles to CC, he worked on sh(1) during the last months. In 8.x, the 'jobs' utility and the implicit 'jobs -n'-like operation before a prompt always cause sh to discard the record of the job and its exit status. In 9.x, sh remembers jobs for which $! has been referenced until they are 'wait'ed for, even if their completion is otherwise reported, while jobs for which $! was not referenced are forgotten as soon as they terminate. This change was made to reduce memory usage from long-running scripts that do not care about job completion, see PR bin/55346. The part of the change that applies to interactive mode may, in fact, be wrong, however useful it may be. Some of the strange differences are due to an inherent race condition: the child process may terminate before or after sh's check just before displaying the prompt. If you do your experiments using scripts instead of in interactive mode, they should work in 8.x as well as in 9.x. -- Jilles Tjoelker