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); }

Replies are listed 'Best First'.
Re: Re: Perl infinite loops!
by marvell (Pilgrim) on Dec 06, 2000 at 21:02 UTC
    It would be worth logging that to a file, or at least terminating the html fully. You wouldn't want a "Document contains no data" situation and no message logged.

    In order to do that, you may have to keep track of where you are. There may be other things to do before you can terminate the html or the script.

    This is not as simple as it seems.

    --
    Brother Marvell

Re: Re: Perl infinite loops!
by silicon39 (Initiate) on Dec 06, 2000 at 22:17 UTC
    This worked great, but I can't get the handler to work. It gives me a "Spurious backslash ignored" on the "$SIG{ALRM} = \&sighandler;" line. I'm not an advanced Perl programmer, so I'm not quite sure where to go, but the alarm() call worked well. Thanks. Ian. BTW, we're still on Perl 4.xxxx (Aaarrrrgh! Don't say anything about this!) :-)
      Iirc, the syntax in Perl 4 is:
      $SIG{ALRM} = 'sighandler';
      Though i could easily be wrong about that :-/