Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Launch process, get PID

by mr_mischief (Monsignor)
on Feb 29, 2008 at 00:32 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found