Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jan 2005 11:14:29 -0600
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Julian Elischer <julian@elischer.org>
Cc:        Harti Brandt <harti@freebsd.org>
Subject:   Re: sh bug?
Message-ID:  <20050128171429.GB70503@dan.emsphone.com>
In-Reply-To: <41FA008D.7030403@elischer.org>
References:  <41F9F2DC.7000907@elischer.org> <20050128094116.B56848@beagle.kn.op.dlr.de> <41FA008D.7030403@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jan 28), Julian Elischer said:
> Harti Brandt wrote:
> >On Fri, 28 Jan 2005, Julian Elischer wrote:
> >
> >JE>however  echo $$
> >JE>and
> >JE>  ( echo $$ )
> >JE>
> >JE>produce the same result.
> >
> >I think that the $$ is expanded in the old shell in any case.
> 
> hence my test of
> ps -l vs (ps -l)
> 
> unfortunatly the shell short circuits that too if it's too simple.

I think POSIX is careful to define a "subshell" as "a duplicate of the
shell environment [... where] changes made are not visible to the
parent shell environment".  They don't mention forking processes, which
allows shell authors to skip forking a separate shell process if they
can determine that there's no need for one.  I don't think there's any
way for a subshell to determine its own pid if you know it's running in
another process, even if it's an asynchronous one.  At least the parent
knows that pid, though, via $!.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050128171429.GB70503>