butters has asked for the wisdom of the Perl Monks concerning the following question:
I would like to execute the shell script as an independent process (i.e. fork then exec), and I don't want the perl script to wait for the shell script to exit before continuing, because it never will (until the perl script sends the right signal). As far as I can tell, the system() function doesn't do the right thing (waits for child to exit), neither does exec() (never returns), and I don't think qx/backticks would work either for the same reason as with system().
Assuming I can execute a shell script "in the background" and continue execution, I then need to get the PID of the child process. How do I do that? I know perl reserves $$ for the PID of the perl script and offers a getppid() function to get the parent PID, but how do I get the child PID?
In case I'm not being clear, this is what I want to do in shell syntax:
my_script.sh & pid=$!
Of course, $! means something completely different in perl. I'm sure this is a not-so-uncommon programming task, so how do I do it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: start process in bg, get child PID
by Sidhekin (Priest) on Jul 17, 2006 at 22:45 UTC | |
|
Re: start process in bg, get child PID
by Hue-Bond (Priest) on Jul 17, 2006 at 22:47 UTC |