Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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!

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
Node Status?
node history
Node Type: modulereview [id://31982]
help
Chatterbox?
[marto]: it's a normal HTML form, with some hidden input fields
[holli]: forgot that thing exists for a moment.
LanX welcome to the twilight zone ...
[Eily]: LanX well since the onion is your eye you should see it everywhere
[marto]: sounds eye watering
[LanX]: oh your talking about my pic?
[Eily]: marto #SoSad
[holli]: duh
[marto]: I expect you to take a nice photo in Glasgow to replace this one :P
[Eily]: LanX yup, saw it when I checked your current rank

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2017-12-14 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (398 votes). Check out past polls.

    Notices?