http://linuxg.net/how-to-transform-a-process-into-a-daemon-in-linux-unix/ gives an example of daemonizing a process in bash:
$ nohup firefox& &> /dev/null
If I am corrrect, the command is the same as "nohup and background a process".
But isn't a daemon more than a nohupped and background process?
What steps are missing here to daemonize a process?
For example, isn't changing the parent process necessary when daemonizing a process? If yes, how do you do that in bash? I am still trying to understand a related reply https://unix.stackexchange.com/a/177361/674.
What other steps and conditions?
See my related question https://stackoverflow.com/q/35705451/156458
Best Answer
From the Wikipedia article on daemon:
In a Unix environment, the parent process of a daemon is often, but not always, the init process. A daemon is usually either created by a process forking a child process and then immediately exiting, thus causing init to adopt the child process, or by the init process directly launching the daemon. In addition, a daemon launched by forking and exiting typically must perform other operations, such as dissociating the process from any controlling terminal (tty). Such procedures are often implemented in various convenience routines such as daemon(3) in Unix.
Read the manpage of the
daemon
function.Running a background command from a shell that immediately exits results in the process's PPID becoming 1. Easy to test:
As you can see, the process is owned by PID 1, but still associated with a TTY. If I log out from this login shell, then log in again, and do
ps
again, the TTY becomes?
.Read here why it's important to detach from TTY.
Using
setsid
(part ofutil-linux
):I think you don't even have to redirect stdin, stdout and stderr.