|No such thing as a small change|
Proc::Daemonby ncw (Friar)
|on Sep 12, 2000 at 00:58 UTC||Need Help??|
Item Description: A small but perfectly formed module for turning your unix process into a Daemon
Review Synopsis: Proc::Daemon a very useful unix utility
Proc::Daemon is a particularly useful module for anyone writing unix daemon's (a program which runs in the background with no user input). It detaches your program from the its parent, allowing it to run undisturbed by the parent, you logging out, or the parent waiting for it to die.
This is a simple module and most of the code in it is contained in The Perl Cookbook, however this module brings it together in a neatly wrapped package so you don't have to remember any of those horrid details (like the double fork, setsid, chdir, reopen STDOUT etc)!
Use it like this
That is it!
You'd quite likely like to re-open STDOUT & STDERR to a log file though, like this :-
I've used it quite a few times now, for writing real daemons, sendmail filters which need to run for a long time (eg email to SMS), for detaching processes from crontab, and for long running CGI programs (which don't need to return a response to the user).
Warning: This module is unlikely to work under Windows, though it probably could be made to.
Verdict: Small but perfectly formed!