On Sunday July 5 2015 11:14, in comp.unix.shell, "John Doe"
<john.doe@notpresent> wrote:
> On 05.07.2015 16:33, Janis Papanagnou wrote:
>> POSIX says: "A subshell environment shall be created as a duplicate of the
>> shell environment, except that signal traps set by that shell environment
>> shall be set to the default values."
>
> For me a subshell was also a shell invoked by typing sh but it look like
> this term is reserved for something slightly different... My bad :(
>
> Is the mechanism behind creating subshell environment generally the same
> as for creating an environment for another process
Yes, generally
> (ie. fork -> exec)
No.
The main shell will fork(). Now there are two processes both running the same
code. Both processes intepret the same shell code. Each process can determine
(based on the return value from fork() which part of shell script it should
interpret. The main shell will continue on with the main part of the script,
and the child process will interpret the part of the script that is
the "subshell".
So, fork(), but no exec().
> but with a few differences (like the one about visibility of
> non-exported variables)?
That's an inherent consequence of the fork() call.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request