Process::Child::Leash - to make sure the child process wont get lost with their parent.
Here is the issue. The parent process is a wrapping bash script around the real process (child). If we stopped the wrapper script. The real process ( child ) will be still remained and running as normal.
How to terminal the parent process and the child process would be stopped as a chain reaction?
+ |--run.sh | |-- perl script.pl
This module will keep an eye on the parent process. When the parent is gone. It will remove the the real process ( child ).
#!/usr/bin/perl use strict; use warnings; use Process::Child::Leash; ... start of the script ... ## run.sh #!/bin/bash export SOMETHING=FOOBAR perl script.pl >> bash run.sh
## run.sh #!/bin/bash export SOMETHING=FOOBAR perl -MProcess::Child::Leash script.pl >> bash run.sh
Timeout after 10 seconds running.
## run.sh #!/bin/bash export CHILD_LEASH_TIMEOUT=10 export DBIC_TRACE=1 perl -MProcess::Child::Leash script.pl perl -MProcess::Child::Leash=timeout,10 script.pl >> bash run.sh
get the pid of run.sh, and kill -9 that pid.
The script.pl process will be terminated.
To install Process::Child::Leash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Process::Child::Leash
CPAN shell
perl -MCPAN -e shell install Process::Child::Leash
For more information on module installation, please visit the detailed CPAN module installation guide.