Nick Hill wrote:
A great solution for administrators would be to set a timer. If the CGI program hasn't given any output for the given time, the CGI process is killed.
As a refinement;
The timer firstly sends a signal to the CGI program which may be caught by the CGI program to generate some form of output. This output will prove whether the http connection is still open. If the CGI program doesn't output anything, a TERM is sent. If still no output and process is still running, a KILL is sent.
A well written CGI will catch the first signal then if it doesn't break the system, output something (eg whitespace if outputting HTML). If the CGI program can't output anything without corrupting the output, a cgi timeout error should be written to a log before cleanly exiting.
A less-well written or hung CGI program will be closed by term or kill.
If the CGI program outputs something in response to the first signal, the timer is reset. Apache will then 'know' whether the http connection is still open. If http closed, will go ahead and kill the CGI process normally. If open, continue to wait for the CGI process. The timer will eventually send a signal again. The sysadmin should be able to set an upper limit on the number of times the first signal is sent before going to term and kill, providing an optional hard limit on how long a CGI can live for.
The first signal can be characterised as a way for apache to request the CGI program says something to prove there is still a connection between the CGI program and the client. There is no requirement for a CGI programmer to catch the signal, however, he may choose to if he expects the CGI program to run for long periods waiting for some external event.
