Some preliminary trials show you're probably right (though I still don't see what could be different on these two systems... maybe a different version of some IPC::* module?). In any case, I was experimenting with the list form of exec for other reasons, and I finally made it through the gotchas:
my @cmd =
('perl',
'-e
print "child: id after exec: $$\n";
print "child: sees processes...\n " ,
grep { m/perl/ }
`ps ax` , "\n";
',
);
print "parent: pre-fork id $$\n";
if ( my $pid = fork ) {
# this is parent code
print "parent: post-fork id $$\n";
print "parent: return from fork is: $pid\n";
sleep 3;
print "parent: still here, with id $$\n";
print "parent: sees processes...\n " ,
grep { m/perl/ }
`ps ax` , "\n";
} else {
# this is child code
die "cannot fork: $!" unless defined $pid;
print "child believes it is: $$\n";
exec {$cmd[0]} @cmd;
}
The gotchas:
- You use the command name first ("indirect object" syntax, ala printing to a file handle), *and* have the command name again inside the list. The second one is what appears in the process listing, the first is the program that's actually run.
- From the shell, you typically do a perl -e 'some code', but if you're going around the shell, those single quotes on the string fed to "-e" just get in the way: @cmd = ('perl', q{-e some code }).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.