I'm trying to use SIGUSR1 to force daemon writed in Perl to execute common tasks. But when Perl receives SIGUSR1 it handles this signal, everything seems to be ok but when it receives more than 1 signal in a few seconds (sometimes even 1 signal) it exits...
#!/usr/bin/perl use strict; use POSIX; my $sigset = POSIX::SigSet->new(&POSIX::SIGUSR1); my $action = POSIX::SigAction->new(\&trap, $sigset, &POSIX::SA_SIGINFO +); POSIX::sigaction(&POSIX::SIGUSR1, $action); #$SIG{USR1} = \&trap; #or install handler like this or "use sigtrap" w +hatever sub trap { print "got signal.\n"; } print "My pid is: $$\n"; while(sleep(1)) { }
$ perl test.pl My pid is: 3188 $ kill -SIGUSR1 3188 got signal. $ kill -SIGUSR1 3188 got signal. ---> script is terminated
C version works without any problems:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> void usr1handler(int signal); int main(void) { signal(SIGUSR1, usr1handler); printf("My pid is: %d\n", getpid()); for(;;) { sleep(1); } return 0; } void usr1handler(int signal) { printf("Got a signal: %d\n", signal); }
$ ./test My pid is: 3188 $ kill -SIGUSR1 3318 Got a signal called: 10 $ kill -SIGUSR1 3318 Got a signal called: 10 $ kill -SIGUSR1 3318 Got a signal called: 10 $ kill -SIGUSR1 3318 Got a signal called: 10 ... it never exits
I'm using perl version v5.12.1 under Linux 2.6.34-12. Any suggestions is much appreciated.

In reply to How to prevent Perl from exit when SIGUSR1 recieved? by cmyker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.