Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Proc::Daemon

by ncw (Friar)
on Sep 12, 2000 at 00:58 UTC ( #31982=modulereview: print w/ replies, xml ) 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

use Proc::Daemon; Proc::Daemon::Init();
That is it!

You'd quite likely like to re-open STDOUT & STDERR to a log file though, like this :-

open(STDOUT, ">>$LOG") or die "Failed to re-open STDOUT to $LOG"; open(STDERR, ">&STDOUT") or die "Failed to re-open STDERR to STDOUT";
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!

Comment on Proc::Daemon
Select or Download Code
RE: Proc::Daemon
by gregorovius (Friar) on Sep 24, 2000 at 12:16 UTC
    > (like the double fork, setsid, chdir, reopen STDOUT etc)

    Now from the parent script you only have to do a:

    system('perl my_daemon.pl');
    and system will return as the forked off child detaches itself from the parent. Useful for when your client program has to start it's own server.

    It's Neat!

Back to Reviews

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2014-08-29 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls