In the following perl script, i intend to timeout the execution of script child_script.pl
if it goes beyond 1 hour. However, the logic doesn't seem to be working as the script is still running after the specified time limit.
Any guesses what am I doing wrong here?
I'm referring to follwing documentation for implementing the timeout in perl: https://docstore.mik.ua/orelly/perl4/cook/ch16_22.htm
It works fine for a standalone command. Is it possible that system
command has an issue ?
MY_CODE (parent_script.pl
)
#!/usr/bin/perl
my $sys_cmd = " perl child_script.pl 2>&1 | tee logfile.txt \n";
print "INFO: Enter alarm..\n";
eval {
local $SIG{ALRM} = sub { die "alarm clock restart" };
alarm 3600; # schedule alarm in 1 hours
eval {
print "INFO: Run script.. \n";
system ($sys_cmd);
};
alarm 0; # cancel the alarm
};
alarm 0; # race condition protection
die if $@ && $@ !~ /alarm clock restart/; # reraise
print "INFO: Exit alarm..\n";