eval {
local $SIG{ALRM}=sub{die "alarm\n"};
alarm 600;
$shell_out = system("./sh1.sh");
alarm 0;
};
if($@) {
die unless $@ eq "alarm\n";
}
It turns out that the shell script is not even executed. | [reply] [d/l] |
The problem with this code is that the shell script isn't being killed.
alarm just arranges for a signal to be delivered to the Perl process, upon which the signal handler throws an exception (die "alarm\n") which in turn causes the Perl script to continue after the eval {} block. The shell script doesn't know anything of this and happily keeps running.
It turns out that the shell script is not even executed.
This is most likely an unrelated problem. Makes me wonder how/why it did run before with the identical system command...
| [reply] [d/l] [select] |
perl -e 'alarm shift @ARGV; exec @ARGV' 100 ./sh1.sh
But I am not able to run this command from my perl script using the system function, within the while loop. That is weird! Any idea why this would happen?
Also, the above command does not kill the process, it just suspends it. Is there a way to kill it?
| [reply] [d/l] |