If you want to detach from the tty, and from session group, then use Proc::Daemon. It handles all the details of the double fork, creating new session group, and closing all filehandles. You will need to reopen stderr or stdout after the process becomes a daemon.