1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| perldoc -q daemon
How do I fork a daemon process?
If by daemon process you mean one thats detached (disassociated from
its tty), then the following process is reported to work on most
Unixish systems. Non‐Unix users should check their Your_OS::Process
module for other solutions.
· Open /dev/tty and use the TIOCNOTTY ioctl on it. See tty for
details. Or better yet, you can just use the POSIX::setsid()
function, so you dont have to worry about process groups.
· Change directory to /
· Reopen STDIN, STDOUT, and STDERR so theyre not connected to the
old tty.
· Background yourself like this:
fork && exit;
The Proc::Daemon module, available from CPAN, provides a function to
perform these actions for you. |