473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

CGI-BIN Forced Termination (Apache)

I've noticed that some scripting languages (PHP, for example) have options
to control whether the script can be terminated by the user clicking STOP on
their browser (or similar mechanisms).

How does this apply to CGI-BINs? Can Apache ever try to terminate a
CGI-BIN, or does it just keep running and its output is discarded? Is there
any signalling?

Nov 20 '06 #1
12 3224
As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
any required cleanup. It could also leave behind a long-running process
using the "at now" command.

Some more info here:

http://mail-archives.apache.org/mod_...@apache.org%3E

David T. Ashley wrote:
I've noticed that some scripting languages (PHP, for example) have options
to control whether the script can be terminated by the user clicking STOP on
their browser (or similar mechanisms).

How does this apply to CGI-BINs? Can Apache ever try to terminate a
CGI-BIN, or does it just keep running and its output is discarded? Is there
any signalling?
Nov 20 '06 #2
"petersprc" <pe*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. ...
Thanks. The info was very helpful.

The hard part for me is that I've searched all over the web and found
various documents that outline the stdin/stdout interface, but process
termination was not discussed anywhere I've found. That seems odd, because
SIGTERM and SIGKILL are part of the interface.

If you can recommend any good books or authoritative references ... I'm just
getting started (never written a compiled 'C' CGI-BIN before ... have just
used scripting languages like PHP, and nearly all of that is handled for
you).

Nov 20 '06 #3
If it's a C program, using a library like this might simplify things:
http://www.boutell.com/cgic/.

If you haven't been here yet, there's an overview of Apache CGI at:
http://httpd.apache.org/docs/1.3/howto/cgi.html.

For internals, you may want to take a look at mod_cgi.c in the Apache
source...

David T. Ashley wrote:
"petersprc" <pe*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. ...

Thanks. The info was very helpful.

The hard part for me is that I've searched all over the web and found
various documents that outline the stdin/stdout interface, but process
termination was not discussed anywhere I've found. That seems odd, because
SIGTERM and SIGKILL are part of the interface.

If you can recommend any good books or authoritative references ... I'm just
getting started (never written a compiled 'C' CGI-BIN before ... have just
used scripting languages like PHP, and nearly all of that is handled for
you).
Nov 21 '06 #4
"petersprc" <pe*******@gmail.comwrote:
>As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
any required cleanup. It could also leave behind a long-running process
using the "at now" command.
Is that promised anywhere? In my experience, the only side effect of the
disconnect is that the sockets feeding stdin and stdout get disconnected.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 21 '06 #5
"Tim Roberts" <ti**@probo.comwrote in message
news:ks********************************@4ax.com...
"petersprc" <pe*******@gmail.comwrote:
>>As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
any required cleanup. It could also leave behind a long-running process
using the "at now" command.

Is that promised anywhere? In my experience, the only side effect of the
disconnect is that the sockets feeding stdin and stdout get disconnected.
Ah, and then we're back again to my weak Unix programming skills.

If the stdin socket gets disconnected, I have no idea what will happen (will
it look like an EOF?). I suppose the cgic library takes care of this part
....

But if the stdout gets disconnected, can my CGI-BIN just go blindly using
printf()'s with no ill effects??? ... I'd guess yes.

But in any case, good references would be always be appreciated. I actually
know nothing about sockets and so forth, except that they exist.

Nov 21 '06 #6
I think a SIGPIPE starts it, and then mod_cgi will detect that it needs
to follow with a kill.

Tim Roberts wrote:
"petersprc" <pe*******@gmail.comwrote:
As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
any required cleanup. It could also leave behind a long-running process
using the "at now" command.

Is that promised anywhere? In my experience, the only side effect of the
disconnect is that the sockets feeding stdin and stdout get disconnected.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 24 '06 #7
It looks like you won't get the SIGPIPE unless you try to write (or
read) from the closed socket. So, your CGI will probably continue until
it attempts some I/O.

petersprc wrote:
I think a SIGPIPE starts it, and then mod_cgi will detect that it needs
to follow with a kill.

Tim Roberts wrote:
"petersprc" <pe*******@gmail.comwrote:
>As far as I know, in the event of a disconnect, Apache will send a
>SIGTERM to the child, and then, if needed, wait up to approximately 3
>seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
>any required cleanup. It could also leave behind a long-running process
>using the "at now" command.
Is that promised anywhere? In my experience, the only side effect of the
disconnect is that the sockets feeding stdin and stdout get disconnected.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 24 '06 #8

"petersprc" <pe*******@gmail.comschreef in bericht
news:11*********************@h54g2000cwb.googlegro ups.com...
>As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
any required cleanup. It could also leave behind a long-running process
using the "at now" command.
Fragments refering to this sequence can be found in the source files of
various modules.
I am unsure whether those apply to handling lost connections or are just
propagating a SIG* to all forked children, CGI included. Chances are
mod_cgid behaves slightly different.
>Is that promised anywhere? In my experience, the only side effect of the
disconnect is that the sockets feeding stdin and stdout get disconnected.
I have seen the same effects.
>I think a SIGPIPE starts it, and then mod_cgi will detect that it needs
to follow with a kill.
Fragment of source code seem to contradict:
* Note that we already ignore SIGPIPE in the core server.

unix/posix notes:
- The proper setting for SIGPIPE is SIG_IGN, if user code changes it
for any of their own processing, it must be restored to SIG_IGN
prior to executing or returning to any apache code.

The latter may indicate behaviour depends on OS.

HansH
Nov 24 '06 #9
David T. Ashley wrote:
I've noticed that some scripting languages (PHP, for example) have options
to control whether the script can be terminated by the user clicking STOP on
their browser (or similar mechanisms).

How does this apply to CGI-BINs? Can Apache ever try to terminate a
CGI-BIN, or does it just keep running and its output is discarded? Is there
any signalling?
Excellent question. Unfortunately, Apache's behavior in exceptional
circumstances like this is not very well documented (and is one of my
biggest gripes :) Most of what I know is from experimentation and
perusing the Apache source code.

As was pointed out earlier, Apache responds to a SIGPIPE, by issuing a
SIGTERM to the CGI, then sleeping for three seconds, and then issuing a
non-interruptable SIGKILL. However, take note that Apache won't receive
the SIGPIPE unless you are writing to STDOUT (this is fairly standard
behavior with socket communication). This means that if the client
disappears while the CGI is performing a time-intensive operation,
there will be no notification of the disconnected socket until after
the CGI again writes to STDOUT. Additionally, if the CGI exceeds
Apache's configured timeout between successive writes to STDOUT, then a
SIGTERM will also be issued.

By not catching (or ignoring) the SIGTERM in either of these two
scenarios, your process will simply be terminated. About the only way
to be reasonably notified of a disconnected socket is to keep writing
to STDOUT. (It may even be possible to write nothing, which could force
a flush of the internal buffer, but I'm not entirely sure if that
actually works.)

--Randall

Nov 29 '06 #10
"R Krause" <rk*****@searstower.orgwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Additionally, if the CGI exceeds
Apache's configured timeout between successive writes to STDOUT, then a
SIGTERM will also be issued.
I've never noticed this configuration directive anywhere. Do you remember
the name? Is it compile-time or in the config file?

Thanks, Dave.

Nov 29 '06 #11
"David T. Ashley" <dt*@e3ft.comschreef in bericht
news:Mb***************@fe74.usenetserver.com...
"R Krause" <rk*****@searstower.orgwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
>Additionally, if the CGI exceeds
Apache's configured timeout between successive writes to STDOUT, then a
SIGTERM will also be issued.

I've never noticed this configuration directive anywhere. Do you remember
the name? Is it compile-time or in the config file?
The name is ... timeout ...
http://httpd.apache.org/docs/2.0/mod/core.html#timeout
.... it's setting matches the impatience of a browser: 5 min
IIRC a script will be killed at the next write to STDOUT following the
timeout period

Limiting the cpu time consummed before complition might eventualy kill a
'silent' script. However, e.g. a script waiting for response from a database
may NOT consume any CPU time (In addition set a timeout per handler for
statement and|or database)
http://httpd.apache.org/docs/2.0/mod...html#rlimitcpu
HansH
Nov 29 '06 #12
petersprc wrote:
As far as I know, in the event of a disconnect, Apache will send a
SIGTERM to the child, and then, if needed, wait up to approximately 3
seconds and send a SIGKILL. Your CGI could handle the SIGTERM and do
any required cleanup. It could also leave behind a long-running process
using the "at now" command.

Some more info here:

http://mail-archives.apache.org/mod_...@apache.org%3E
Excellent link. That's still one of my fave bug reports for Apache 1.3.
It's interesting to think it was submitted in 2001 and yet that feature
has still never been implemented properly to date. :)

Btw, I'd never heard anyone suggest 'at now' before. That sounds like a
very suitable workaround. I'll have to give it a try.

--Randall

Nov 30 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DeepBleu | last post by:
When one is using an HTML form via a web broswer, the user submits the form contents and these are passed to a CGI Python script on the web server. I need to write a client script that connects to...
2
by: JR | last post by:
Hi. I have a CGI script that will need to call itself an unknown number of times, to add rows, run queries, etc. At the bottom of the output that is produced by the script, there are four...
2
by: J Krugman | last post by:
I have a form with a couple of submit buttons, plus a "pseudolink" that is also supposed to submit the form; the submitted form data feeds to a CGI script. The two submit buttons have the name...
11
by: comp.lang.php | last post by:
On one of my sites, I have a TCL CGI script that has a security hole in spite of it having effective server-side validation (the fact that it's CGI IS its security hole). The front end is a PHP...
10
by: jason_box | last post by:
Hello, I was wondering if there was a way to have a javacript be activated by an input button that would call to a cgi program and querey every 10minutes and the cgi would update the page without...
14
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in...
11
by: Cecil Westerhof | last post by:
I have a cgi-script dat uses the modules cgi, os, sys and time. Offcourse I can not time the time used to import time, but os and sys do not take more as a millisecond. My script itself takes 3 or...
3
by: Adrian Smith | last post by:
While waiting for my paid-for web-hosting company to get back to me about my difficulties running python scripts on their servers......
6
by: Michael Tissington | last post by:
Using Visual Studio 2008 can someone point me to an example to create a cgi web service in C# ? Thanks.
0
by: d0353101 | last post by:
I am having login.cgi. user enter id and password. if ok it redirects to main.cgi with user_id as main_page.cgi?user_id=$user_id. main.cgi is having left menu and right part is for doing some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.