New to perl trying to fix zombie process bug.I have a script that makes a timed system call in an eval block.
my $timeout = timed_system_call("/subprocess_a.rb", 3);
if ($timeout == 0) {
print "success\n";
}
else {
print "timed out\n";
}
sub timed_system_call {
my $command = shift;
my $timeout = shift; # seconds
my $alarm = 0;
eval {
local $SIG{ALRM} = sub {$alarm = 1; kill -15, $child_pid;};
alarm $timeout;
system($command);
alarm 0;
};
die $command . " failed with " . $@ if $@ && $alarm != 1; #if alar
+m is not 1, then something else caused exit e.g(ctrl-c)
alarm 0;
return $alarm;
}
I need to, ensure the system() call subprocess is killed after timeout, without killing the parent process. On timeout the program should continue to the else block.