develooper Front page | perl.perl5.porters | Postings from February 2015

Re: [perl #123775] Args to 'system' not evaluated before forking,making $$ wrong

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
February 14, 2015 00:16
Subject:
Re: [perl #123775] Args to 'system' not evaluated before forking,making $$ wrong
Message ID:
CAHhgV8i6CpacE-KbD8fJzwUZe+YOdhVwWSk0qxQX7bDM7nWJmw@mail.gmail.com
On Sat, Feb 14, 2015 at 1:02 AM, James E Keenan via RT <
perlbug-followup@perl.org> wrote:

> On Fri Feb 13 15:40:38 2015, LeonT wrote:
> > On Mon, Feb 9, 2015 at 10:56 PM, via RT <perlbug-followup@perl.org>
> > wrote:
> >
> > > The original problem which led me to this was:
> > >
> > > system "ps","-p",$$,"-o","pid,etime,bsdtime,c,rss";  # always shows
> > > wrong values
> > >
> > > The problem appears to be that $$ is not correct when passed to
> > > system().
> > > I'm guessing it evaluates to the pid of an internaly-created child
> > > process.
> > >
> > > Can 'system' (and any other forking operators) be made to
> > > evaluate their arguments *before* forking?
> > >
> > > #!/usr/bin/perl
> > > use strict; use warnings;
> > >
> > > my $copy_of_pid = $$;
> > > print "Perl process is $$\n";
> > >
> > > system "/bin/echo", 'echo: $$ =', $$;
> > > system "/bin/echo", 'echo: $copy_of_pid =', $copy_of_pid;
> > >
> >
> > Fix attached.
> >
> > Leon
>
> In the parts of the patch where you are adding lines to source code or
> tests, could you use space characters rather than hard-tabs for leading
> whitespace, so as to make the appearance tidier?
>

Perl's source consistently uses a convention of tabstop=8 and
soft-tabstop=4, which is like "indent 4 spaces, but replace every 8 spaces
with a tab". I'm quite sure space- and tab-lovers alike are not
particularly fond of this mixed use whitespace, but it's a bit late to
change that for the entire codebase. I had actually paid attention to be
consistent (the testfile doesn't have a modeline).

Leon

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About