develooper Front page | perl.perl5.porters | Postings from January 2014

Re: [perl #121105] During a system(), unquoted Perl vars areevaluated _after_ the fork() call

Thread Previous | Thread Next
Dave Mitchell
January 30, 2014 15:00
Re: [perl #121105] During a system(), unquoted Perl vars areevaluated _after_ the fork() call
Message ID:
On Thu, Jan 30, 2014 at 01:53:35PM -0000, Father Chrysostomos wrote:
> Gian Piero Carrubba wrote:
> > $ perl -l
> > print $$;
> > system 'echo', "$$";
> > system 'echo', $$;
> > 32480
> > 32480
> > 32488
> > 
> > The last pid printed (from the system() with unquoted $$) is the pid of
> > the child process, not the one of the parent.
> I think this is related to #104084.

It bisects to

    commit 0e21945565eb4664d843bb819fb032cedee4d5a6
    Author: Max Maischein <>
    Date:   Sun May 22 21:36:57 2011 -0700

    Turn $$ into a magical readonly variable that always fetches getpid() instead of caching it
    The intent is that by not caching $$, we eliminate one opportunity for bugs:
    If one embeds Perl or uses XS and calls fork(3) from C, Perls notion of $$
    may go out of sync with what getpid() returns. By always fetching the
    value of $$ via getpid(), this bug opportunity is eliminated. The overhead
    of always fetching $$ should be small and is likely only used for tempfile
    creation, which should be dwarfed by file system accesses.

Maybe system() should call get magic on its args *before* forking?

In economics, the exam questions are the same every year.
They just change the answers.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About