Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl Daemons and SIGHUP

by cdarke (Prior)
on Feb 24, 2010 at 13:56 UTC ( [id://825076]=note: print w/replies, xml ) Need Help??


in reply to Perl Daemons and SIGHUP

Like me you probably found Can't catch signals after an exec? which recommends using the POSIX routines. Unfortunately you have an error in your SigAction->new, you should supply a reference to the handler, not its name:
my $sigset = POSIX::SigSet->new(); my $action = POSIX::SigAction->new( \&sigHUP_handler, $sigset, &POSIX::SA_NODEFER ); POSIX::sigaction(&POSIX::SIGHUP, $action);
I reproduced a simplified version of your problem using $SIG{HUP} and this fixed it.

Replies are listed 'Best First'.
Re^2: Perl Daemons and SIGHUP
by explodec14 (Novice) on Feb 24, 2010 at 14:58 UTC

    well i tried what you've fixed. but still, after the doing the exec call, the process dies.

    It happens also when i use the Daemon::Generic package.

    10x
      Might I suggest that you try this without any Daemon modules? Just get it running as an ordinary background job using myscript.pl &, because that did not work previously. Even if it still does not work then at least you would have eliminated a chunk of software and we might be able to tie down a simplified version.
      If it does work without the Daemon modules then we know where to look next.
        Hi everyone -

        I am glad to announce that the problem is solved! Well, the reason the process died is bebcaus the exec call failed. And why is that? because the process tried to invoke the script by using the wrong path.

        I will explain:
        As you all surely know, once the process has been daemonized it runs under / directory (root directory). The process then tried to invoke the script by using relative path and not absolute path as it should have done.
        This caused the exec call to fail and thus the process couldn't be restarted. By the way, once the process receives HUP signal it will eventually die anyway. To prevent this you can start it in the signal handler and thus a new process will be created along with this that died.

        Thank you all for your help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://825076]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found