Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

%ENV setting not exported to child process?

by saintmike (Vicar)
on Jan 12, 2006 at 22:48 UTC ( [id://522833]=perlquestion: print w/replies, xml ) Need Help??

saintmike has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

can you think of a reason why setting $ENV{foo} wouldn't be exported to a child process? Funny, I have two versions of perl-5.8.5, compiled with different threading options, which show different results:

/path1/perl (5.008005): Export OK /path2/perl (5.008005): Export not OK
on
$ENV{foo} = "abc"; my $out = `echo \$foo`; print "$^X ($]): Export ", $out ne "abc\n" ? "not " : "", "OK\n";
The difference between the two binaries is that one got linked to linuxthreads, while the other one uses pthreads, both on FreeBSD 4.x.

Weird, isn't it? Doesn't setting %ENV just translate to a setenv() at C-level?

Replies are listed 'Best First'.
Re: %ENV setting not exported to child process?
by bluto (Curate) on Jan 13, 2006 at 00:20 UTC
    Yeah it's wierd. FWIW, it's hard to tell from your example if the problem is really related to exporting (i.e. you aren't checking $?; you should print the contents of $out; you should probably use the fullpath to 'echo' and not rely on the shell built-in or your PATH).
      Just checked, it's not related to the full path to echo, and $? is 0.
Re: %ENV setting not exported to child process?
by olivierp (Hermit) on Jan 13, 2006 at 15:31 UTC
    I may be completely wrong, but isn't FreeBSD's pthreads actually the same process, so the child is actually seeing the same %ENV as perl itself ?
    HTH
    --
    Olivier
      Well, but system() and `...` aren't running in a new thread, they're forking off a new process. How would that be related to the threading model?

      The only way I can see this happening is that perl doesn't use setenv() if a certain threading model is enabled, similar to what's been described here.

Re: %ENV setting not exported to child process?
by Argel (Prior) on Jan 16, 2006 at 22:01 UTC
    I know when forking the child should inherit the environment of the parent. But does that rule apply to threads?

    -- Argel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://522833]
Approved by Paladin
Front-paged by aufflick
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found