Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Launch process, get PID

by mr_mischief (Monsignor)
on Feb 29, 2008 at 00:32 UTC ( #671064=note: print w/ replies, xml ) Need Help??


in reply to Launch process, get PID

What you want is to explicitly fork() then exec(). That's the tried-and-true traditional way to launch another process on Unixy systems, and fork() returns the child's PID in the parent (and 0 in the child, or undef if the fork() failed).

This code is simple, but it shows the concept.

if ( my $pid = fork() ) { my $pid_of_child_that_finished = wait(); my $status_code_of_child = $?; # or $CHILD_ERROR_NATIVE } elsif ( defined $pid ) { exec( '/bin/ls' ); } else { warn "Something broke: can't fork()!\n"; } # continue processing in the parent after child is done


Comment on Re: Launch process, get PID
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://671064]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-07-03 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls