Auto kill any children before exiting from process
This commit is contained in:
parent
03c2ee0d64
commit
d94ec26792
@ -85,6 +85,24 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
# Kill any children still running
|
||||||
|
for my $proc (values %running){
|
||||||
|
if ( $proc->is_child($$) ){
|
||||||
|
print "Killing: $proc\n";
|
||||||
|
$proc->kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub is_child {
|
||||||
|
my ($self, $parent_pid)= @_;
|
||||||
|
die "usage: \$safe_proc->is_child()" unless (@_ == 2 and ref $self);
|
||||||
|
return ($self->{PARENT} == $parent_pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Find the safe process binary or script
|
# Find the safe process binary or script
|
||||||
my @safe_process_cmd;
|
my @safe_process_cmd;
|
||||||
my $safe_kill;
|
my $safe_kill;
|
||||||
@ -172,6 +190,7 @@ sub new {
|
|||||||
SAFE_WINPID => $winpid,
|
SAFE_WINPID => $winpid,
|
||||||
SAFE_NAME => $name,
|
SAFE_NAME => $name,
|
||||||
SAFE_SHUTDOWN => $shutdown,
|
SAFE_SHUTDOWN => $shutdown,
|
||||||
|
PARENT => $$,
|
||||||
}, $class);
|
}, $class);
|
||||||
|
|
||||||
# Put the new process in list of running
|
# Put the new process in list of running
|
||||||
@ -203,6 +222,7 @@ sub timer {
|
|||||||
({
|
({
|
||||||
SAFE_PID => $pid,
|
SAFE_PID => $pid,
|
||||||
SAFE_NAME => "timer",
|
SAFE_NAME => "timer",
|
||||||
|
PARENT => $$,
|
||||||
}, $class);
|
}, $class);
|
||||||
|
|
||||||
# Put the new process in list of running
|
# Put the new process in list of running
|
||||||
|
Loading…
x
Reference in New Issue
Block a user