Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: How to get a persistent daemons after exiting the session?

by rob_au (Abbot)
on Mar 11, 2003 at 22:21 UTC ( [id://242171]=note: print w/replies, xml ) Need Help??


in reply to Re: How to get a persistent daemons after exiting the session?
in thread How to get a persistent daemons after exiting the session?

can't figure a good way to hold the pidfile locked while i daemonize since Proc::Daemon closes open files (losing the locks)

This is expected behaviour for Proc::Daemon or indeed any daemon written in line with the recommendations for daemon processes in "Advanced Programming in the Unix Environment" by W. Richard Stevens - This behaviour results from the closure of all open file handles, specifically, the line:

foreach $i (0 .. OpenMax) { POSIX::close($i); }

The best way to avoid this behaviour affecting your lock files is to acquire the lock after becoming a daemon process. If this lock acquisition fails, write to the application log and exit - This is relatively standard practice. For example, the Apache web server does something similar with regard to open a listening socket connection - The server will daemonise before opening this socket, which if fails, will write the error to the log file and exit.

Proc::PID::File has some issues

I would note that there is also a race condition between the opening of the file and acquisition of the lock and that the return value of the flock function is not checked to ensure that the lock acquisition has been successful.

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000001000111100"))'

Replies are listed 'Best First'.
Re: Re: Re: How to get a persistent daemons after exiting the session?
by zengargoyle (Deacon) on Mar 11, 2003 at 23:16 UTC

    yes, i know why the files are closed and the locks lost. i'm trying to figure out if it's worth trying to work around by tweaking the fork code. i'm just a little worried about the time between closing all files and reaquiring the pidfile and having logging configured (for any error messages). i think i might just fall back on 'set logging to STDOUT and run with -nofork' if things don't appear to be working.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found