Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://671064]
and all is quiet...

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

    Results (612 votes). Check out past polls.