dasibre has asked for the wisdom of the Perl Monks concerning the following question:
New to perl trying to fix zombie process bug.I have a script that makes a timed system call in an eval block.
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.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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: eval system timeout child process
by Marshall (Canon) on Sep 29, 2016 at 21:46 UTC | |
|
Re: eval system timeout child process
by Lotus1 (Vicar) on Sep 29, 2016 at 21:26 UTC | |
by dasibre (Initiate) on Sep 30, 2016 at 00:04 UTC | |
|
Re: eval system timeout child process
by andal (Hermit) on Sep 30, 2016 at 06:52 UTC | |
by dasibre (Initiate) on Sep 30, 2016 at 09:44 UTC | |
by RonW (Parson) on Sep 30, 2016 at 18:07 UTC |