CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
socket server and sigalrm


New User

Jan 6, 2009, 12:41 PM

Post #1 of 2 (302 views)
socket server and sigalrm Can't Post

I have some server code based on HTTP:Daemon (on Linux) that works fine except when I try to trap SIGALRM. When I trap the signal, the handler runs once and then the program exits silently. I've grepped through most of the module sources I'm using and haven't found any of them using SIGALRM. If I comment out the networking and keep the daemon alive with a while(1) loop it works fine.

Alarm code is:

$SIG{'ALRM'} = \&logme; 
setitimer(TIMER_REAL, 10, 10);
sub logme { log->info("alarm handler"); }

I'm not really sure how to even debug this.

New User

Jan 6, 2009, 1:12 PM

Post #2 of 2 (299 views)
Re: [jimmy5804] socket server and sigalrm [In reply to] Can't Post

Here's a simple test case to illustrate the problem. As shown, the program dies after the first run of the hook. Comment out setitimer() and it runs forever (obviously you wouldn't normally print to STDOUT in a daemon). This is 5.8.8 btw.


use IO::Socket;
use Time::HiRes qw(setitimer ITIMER_REAL time);

defined(my $pid=fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";

$SIG{'ALRM'} = \&logme;
setitimer(ITIMER_REAL, 10, 10);

my $sock = new IO::Socket::INET (
"Proto" => "tcp",
"LocalPort" => 8819,
"Reuse" => 1,
"Listen" => 1
) or die "Server croaked";

while($client = $sock->accept())

sub logme {
print "hello\n";


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives