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

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

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
February 14, 2015 00:02
Subject:
[perl #123775] Args to 'system' not evaluated before forking, making $$ wrong
Message ID:
rt-4.0.18-29049-1423872156-849.123775-15-0@perl.org
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?

Thank you very much.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123775

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