in reply to start process in bg, get child PID
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().
Oddly, although you know you want fork and exec, it isn't in this list of possible alternatives. You will be glad to know that fork gives the child PID to the parent process. Very roughly, that could be:
defined (my $pid = fork) or die "fork: $!"; if ($pid) { ## child exec '/bin/sh' or die "exec: $!"; } ## parent sleep 10; kill 2, $pid;
Update: Fixed a nasty fork or die. Thanks to Sidhekin
--
David Serrano
|
|---|