http://qs1969.pair.com?node_id=45236


in reply to Perl infinite loops!

Somewhere near the top of your cgi script you could put something like the following:
alarm(180); # stop script after 3 minutes
Which will kill the cgi script's process (with a SIGALRM) 3 minutes after execution of that line of code.

You could even go as far as printing a warning message if the script is killed this way:
$SIG{ALRM} = \&sighandler; sub sighandler() { print "WARNING: Script timed out or was killed\n"; exit (0); }