http://qs321.pair.com?node_id=124250


in reply to Re: Starting a process in the background that lives after perl dies.
in thread Starting a process in the background that lives after perl dies.

Don't forget to close STDIN, STDOUT and STDERR, and change pwd to "/" so you don't end up with a background process keeping you from unmounting some filesystem later on. I use the following at daemon start time.
my $pid = fork(); if($pid != 0){ exit 0; } chdir "/"; close STDOUT; close STDERR; close STDIN; POSIX::setsid(); # this takes care of controlling terminals
Stevens covered this pretty well, I think it was "Advanced Programming in the UNIX Environment" or some such.