During the test period, I noticed something strange. When using this code, my whole script is 'respawned' instead of the single command I want to check for timeout. Maybe the code is wrong. All I need is to run a single command and wait for the result withing a given timeout. If the command takes too long I want to kill it. The script is running on AIX 4.3.3 & 5.2. Perl version is 5.8. Any suggestions ? Thank you very much.$cmd="myCommand"; # Timeout evaluation: eval { # Set action to be done when alarm occurs: local $SIG{ALRM} = sub { die "ALARM_COMMAND_TIMEOUT" }; # Schedule alarm in $CMD_TIMEOUT seconds: alarm($CMD_TIMEOUT); ### execute the command that can block $childPID = open(PIPE, "-|"); ### Unable to create child process unless(defined $childPID) { close(PIPE); die "ERROR_FORK_PROCESS: $!\n"; } ### Child Process Created ... execute command unless($childPID) { exec($cmd) or die "ERROR_OPEN_PIPE : $!\n"; ### Unable to create child process } wait; alarm(0); close(PIPE); }; alarm(0);
In reply to Timeout with SIG{ALRM} not working as expected by MorgothSauron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |