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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



jimmy5804
New User

Jan 6, 2009, 12:41 PM

Post #1 of 2 (301 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:

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


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


jimmy5804
New User

Jan 6, 2009, 1:12 PM

Post #2 of 2 (298 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.


Code
#!/usr/bin/perl 

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