Earl Hood > Proc-Daemon-0.03 > Proc::Daemon

Download:
Proc-Daemon-0.03.tar.gz

Dependencies

Annotate this POD (1)

CPAN RT

New  4
Open  0
View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Proc::Daemon - Run Perl program as a daemon process

SYNOPSIS ^

    use Proc::Daemon;
    Proc::Daemon::Init;

DESCRIPTION ^

This module contains the routine Init which can be called by a Perl program to initialize itself as a daemon. A daemon is a process that runs in the background with no controlling terminal. Generally servers (like FTP and HTTP servers) run as daemon processes. Note, do not make the mistake that a daemon == server.

The Proc::Daemon::Init function does the following:

  1. Forks a child and exits the parent process.
  2. Becomes a session leader (which detaches the program from the controlling terminal).
  3. Forks another child process and exits first child. This prevents the potential of acquiring a controlling terminal.
  4. Changes the current working directory to "/".
  5. Clears the file creation mask.
  6. Closes all open file descriptors.

You will notice that no logging facility, or other functionality is performed. Proc::Daemon::Init just performs the main steps to initialize a program as daemon. Since other funtionality can vary depending on the nature of the program, Proc::Daemon leaves the implementation of other desired functionality to the caller, or other module/library (like Sys::Syslog).

There is no meaningful return value Proc::Daemon::Init. If an error occurs in Init so it cannot perform the above steps, than it croaks with an error message. One can prevent program termination by using eval.

OTHER FUNCTIONS ^

Proc::Daemon also defines some other functions. These functions can be imported into the callers name space if the function names are specified during the use declaration:

Fork

Fork is like the built-in fork, but will try to fork if at all possible, retrying if necessary. If not possible, Fork will croak.

OpenMax

OpenMax returns the maximum file descriptor number. If undetermined, 64 will be returned.

NOTES ^

AUTHOR ^

Earl Hood, earl@earlhood.com

http://www.earlhood.com/

CREDITS ^

Implementation of Proc::Daemon derived from the following sources:

DEPENDENCIES ^

Carp, POSIX.

SEE ALSO ^

POSIX, Sys::Syslog

syntax highlighting: