1Daemon(3)             User Contributed Perl Documentation            Daemon(3)
2
3
4

NAME

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

SYNOPSIS

9           use Proc::Daemon;
10           Proc::Daemon::Init;
11

DESCRIPTION

13       This module contains the routine Init which can be called by a Perl
14       program to initialize itself as a daemon.  A daemon is a process that
15       runs in the background with no controlling terminal.  Generally servers
16       (like FTP and HTTP servers) run as daemon processes.  Note, do not make
17       the mistake that a daemon == server.
18
19       The Proc::Daemon::Init function does the following:
20
21       1   Forks a child and exits the parent process.
22
23       2   Becomes a session leader (which detaches the program from the con‐
24           trolling terminal).
25
26       3   Forks another child process and exits first child.  This prevents
27           the potential of acquiring a controlling terminal.
28
29       4   Changes the current working directory to "/".
30
31       5   Clears the file creation mask.
32
33       6   Closes all open file descriptors.
34
35       You will notice that no logging facility, or other functionality is
36       performed.  Proc::Daemon::Init just performs the main steps to initial‐
37       ize a program as daemon.  Since other funtionality can vary depending
38       on the nature of the program, Proc::Daemon leaves the implementation of
39       other desired functionality to the caller, or other module/library
40       (like Sys::Syslog).
41
42       There is no meaningful return value Proc::Daemon::Init.  If an error
43       occurs in Init so it cannot perform the above steps, than it croaks
44       with an error message.  One can prevent program termination by using
45       eval.
46

OTHER FUNCTIONS

48       Proc::Daemon also defines some other functions.  These functions can be
49       imported into the callers name space if the function names are speci‐
50       fied during the use declaration:
51
52       Fork
53
54       Fork is like the built-in fork, but will try to fork if at all possi‐
55       ble, retrying if necessary.  If not possible, Fork will croak.
56
57       OpenMax
58
59       OpenMax returns the maximum file descriptor number.  If undetermined,
60       64 will be returned.
61

NOTES

63       ·   Proc::Daemon::init is still available for backwards capatibilty.
64           However, it will not perform the double fork, and will return the
65           session ID.
66

AUTHOR

68       Earl Hood, earl@earlhood.com
69
70       http://www.earlhood.com/
71

CREDITS

73       Implementation of Proc::Daemon derived from the following sources:
74
75       ·   Advanced Programming in the UNIX Environment, by W. Richard
76           Stevens.  Addison-Wesley, Copyright 1992.
77
78       ·   UNIX Network Progamming, Vol 1, by W. Richard Stevens.  Prentice-
79           Hall PTR, Copyright 1998.
80

DEPENDENCIES

82       Carp, POSIX.
83

SEE ALSO

85       POSIX, Sys::Syslog
86
87
88
89perl v5.8.8                       2003-06-19                         Daemon(3)
Impressum