Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: exec sometimes changes pid

by doom (Deacon)
on Aug 03, 2009 at 00:34 UTC ( #785307=note: print w/replies, xml ) Need Help??

in reply to Re: exec sometimes changes pid
in thread exec sometimes changes pid

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 }).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://785307]
[Discipulus]: see Re: from txt file to array erix
[erix]: yeah, I ask for the text (I don't see signatures)
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.
[uhClem]: And besides, the objection to it was off-topic.
[Discipulus]: 1nickt hide signature is a positive action; i think is not a solution here

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-06-22 12:33 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.