Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Proc::Daemon

by ncw (Friar)
on Sep 12, 2000 at 00:58 UTC ( [id://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!

Replies are listed 'Best First'.
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!

Log In?
Username:
Password:

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

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

    No recent polls found