hakkr,
sevensven's code is just a test that illustrates how to use those signal handlers, and it will let you verify that your server passes the signals to your script appropriately. You don't
need to constantly print anything -- that was just part of the test. So, don't slow yourself down needlessly, okay?
On the other hand, if your script will run for quite a while -- 2+ minutes -- then you really should be printing some invisible characters to keep the browser from timing out. Just another CGI trick...
Check out
sigtrap. After checking out this doc, I'm about to replace all my signal handler code with one sigtrap line!
Also, check out the great info in the Camel 3 book pp. 412-417 about handling signals and some more specific info on zombie processes.
One last thing:
SIG{PIPE} is the signal which should get sent when a user hits the STOP button on their browser. You really should handle those other important signals too, but
SIG{PIPE} is the enemy you're dealing with specifically.
Update: Here's my new and improved signal handler.
use Carp;
use sigtrap qw(handler croak normal-signals error-signals);
Also, the signal I get when I hit the STOP button is actually
$SIG{TERM}, not
$SIG{PIPE}. So, I lied earlier. :)