in reply to perl daemon

Details for writing daemons differ between Unices (including Linux) and WinNT/Win2000/WinXP.

Lincoln Stein covers the basics for Unix in Chapter 10, Forking Servers and the inetd Daemon, and Chapter 14, Bulletproofing Servers, in Network Programming with Perl.

There's a bit more to being a well-behaved daemon than is obvious at first glance. On page 312, Stein notes that a well-behaved daemon should:

  1. "Autobackground" itself (fork/parent-exit), then close file handles and lose any assocition with a controlling terminal.
  2. Change the current working directory to a known directory.
  3. Change the file creation mask to a known state.
  4. Set the PATH to a known state.
  5. Record its process ID in a known place
  6. Optionally use syslog to write diagnostics
  7. Optionally handle HUP signals (e.g. to reload configuration files)
  8. Options use chroot()
He then spends the better part of a chapter fleshing that out and giving examples.

Replies are listed 'Best First'.
Re: Re: perl daemon
by DrManhattan (Chaplain) on Apr 05, 2003 at 04:57 UTC
    I've been quite impressed with Net::Daemon so far. It does most of what you listed there right out of the box and appears to be quite portable (though admittedly I have not tried to run it under windows).

    -Matt