no
  N   §ˆl–Ãa¾”ªe¶¥	@;q¦î2Ê˜´o�þE$Ž¬ÙBü²�Çˆ�üÿÔ„]e¿Óa–ßi~” T¾R( 	ÅåÆÙ¸)‹FÿÐ -×    §
=head1 NAME

Proc::Daemon - Run Perl program(s) as a daemon process.




=head1 SYNOPSIS

    use Proc::Daemon;

    $daemon = Proc::Daemon->new(
        work_dir => '/my/daemon/directory',
        .....
    );

    $Kid_1_PID = $daemon->Init;

    unless ( $Kid_1_PID ) {
        # code executed only by the child ...
    }

    $Kid_2_PID = $daemon->Init( { 
                    work_dir     => '/other/daemon/directory',
                    exec_command => 'perl /home/my_script.pl',
                 } );

    $pid = $daemon->Status( ... );

    $stopped = $daemon->Kill_Daemon( ... );




=head1 DESCRIPTION

This module can be used by a Perl program to initialize itself as a daemon
or to execute (C<exec>) a system command as daemon. You can also check the status
of the daemon (alive or dead) and you can kill the daemon.

A daemon is a process that runs in the background with no controlling
terminal. Generally servers (like FTP, HTTP and SIP servers) run as daemon
processes. Do not make the mistake to think that a daemon is a server. ;-)

Proc::Daemon does the following:


=over 4

=item 1

The script forks a child.


=item 2

The child changes the current working directory to
the value of 'work_dir'.


=item 3

The child clears the file creation mask.


=item 4

The child becomes a session leader, which detaches the program from the
controlling terminal.


=item 5

The child forks another child (the final daemon process). This prevents
the potential of acquiring a controlling terminal at all and detaches the
daemon completely from the first parent.


=item 6

The second child closes all open file descriptors (unless you define
C<dont_close_fh> and/or C<dont_close_fd>).


=item 7

The second child opens STDIN, STDOUT and STDERR to the location defined in the
constructor (C<new>).


=item 8

The second child returns to the calling script, or the program defined
in 'exec_command' is executed and the second child never returns.


=item 9

The first child transfers the PID of the second child (daemon) to the
parent. Additionally the PID of the daemon process can be written into a file
if 'pid_file' is defined. Then the first child exits.


=item 10

If the parent script is looking for a return value, then the PID(s) of the
child/ren will be returned. Otherwise the parent will exit.

=back


NOTE: Because of the second fork the daemon will not be a session-leader and
therefore Signals will not be send to other members of his process group. If
you need the functionality of a session-leader you may want to call
POSIX::setsid() manually at your daemon.


INFO: Since C<fork> is not performed the same way on Windows systems as on
Linux, this module does not work with Windows. Patches appreciated!




=head1 CONSTRUCTOR


=over 4

=item new ( %ARGS )

The constructor creates a new Proc::Daemon object based on the hash %ARGS. The
following keys from %ARGS are used:


=over 8

=item work_dir

Defines the path to the working directory of your daemon. Defaults to C</>.


=item setuid

Sets the real user identifier (C<< $< >>) and the effective user identifier
(C<< $> >>) for the daemon process using C<POSIX::setuid( ... )>, in case you
want to run your daemon under a different user from the parent. Obviously the
first user must have the rights to switch to the new user otherwise it will
stay the same. It is helpful to define the argument C<setuid> if you start your
script at boot time by init with the superuser, but wants the daemon to run
under a normal user account.

=item setgid

Sets the real group identifier (C<$(>) and the effective group identifier
(C<$)>) for the daemon process using C<POSXI::setgid( ... )>, just like
C<setuid>.  As with C<setuid>, the first user must have the rights to switch to the
new group, otherwise the group id will not be changed.


=item child_STDIN

Defines the path to STDIN for your daemon. Defaults to C</dev/null>. Default
Mode is '<' (read). You can define other Mode the same way as you do using
Perls C<