Bill Moseley wrote:

> At 02:02 PM 02/26/01 +0000, Steve Hay wrote:
> >I have a script which I wish to run under either mod_perl or CGI which does
> >little more than display content and I would like it to stop when the user
> >presses Stop, but I can't get it working.
>
> You need to do different things under mod_perl and mod_cgi.  Refer to the
> Guide for running under mod_perl -- you probably should check explicitly
> for an aborted connection as the guide shows.

Oh dear.  The program has to run on various different machines around the place,
some of which run Apache/mod_perl and some of which run Microsoft IIS/CGI, so I
really want one solution which works in both environments if at all possible.

> [This is all from my memory, so I hope I have the details correct]
>
> Under mod_cgi Apache will receive the SIGPIPE when it tries to print to the
> socket.  Since your CGI script is running as a subprocess (that has been
> marked "kill_after_timeout", I believe), apache will first close the pipe
> from your CGI program, send it a SIGTERM, wait three seconds, then send a
> SIGKILL, and then reap.  This all happens in alloc.c, IIRC.
>
> This is basically the same thing that happens when you have a timeout.
>
> So, you can catch SIGTERM and then have three seconds to clean up.  You
> won't see a SIGPIPE unless you try to print in that three second gap.

I'm fairly sure the program does print in any given three second gap -- I see
the "x"s appearing in my browser window (since output is "unbuffered") at the
rate of two or three per second, so I really should get the SIGPIPE.

I've also tried adding in a similar handler to try and catch a SIGTERM and
exit(), but that doesn't seem to work either.

Has anybody else had any luck responding to "Stop" on NT?

Cheers,
Steve Hay


Reply via email to