#!/usr/bin/perl
use strict;
print "Content-type: text/plain\n\n";
$| = 1; #dont buffer output to stdout
# playing with signals, no luck
sub signal {
print LOG "got signal, shuting down\n";
close LOG;
}
$SIG{INT} = \&signal;
$SIG{PIPE} = \&signal;
$SIG{ALRM} = \&signal;
$SIG{HUP} = \&signal;
# check until when did the CGI run with log file
open(LOG, '>/usr/local/apache/cgi-bin/log.txt') or die("open : $!");
# dont want LOG file buffering
my $old_fh = select(LOG);
$| = 1;
select($old_fh);
my $out = "running cgi, placing outout here\n";
for (my $i=0;$i<20;$i++) {
# toogle comments in the 2 following lines to see the CGI stop
# print "[$i] test cgi
\n";
$out .= "[$i]test cgi
\n";
print LOG "[$i] test cgi\n";
sleep(1);
}
print LOG $out;
close LOG;