4 ms·
An update to the previous comment. It is true that typing `nohup emacs &` directly into the shell does not help, i.e., Emacs dies when the shell dies. Example:
by susam 5y ago
An update to the previous comment. It is true that typing `nohup emacs &` directly into the shell does not help, i.e., Emacs dies when the shell dies. Example:
$ cat /etc/debian_version
10.0
$ $SHELL --version | head -n 1
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
$ nohup emacs &
$ ps -ef | grep emacs | grep -v grep
susam 22210 22046 2 13:59 pts/0 00:00:00 emacs
$ ps -ef | grep 22046 | grep -v grep
susam 22046 22042 0 13:45 pts/0 00:00:00 bash
susam 22210 22046 0 13:59 pts/0 00:00:00 emacs
susam 22224 22046 0 14:00 pts/0 00:00:00 ps -ef
The parent of the emacs process is still bash, so when bash dies, Emacs dies too.
However, invoking `nohup emacs &` from another shell script does work. The PPID of Emacs gets assigned to 1 and Emacs continues to keep running even after killing the shell. Example:
$ bash -c 'nohup emacs &'
$ ps -ef | grep emacs | grep -v grep
susam 22229 1 2 14:02 pts/0 00:00:00 emacs
$ dash -c 'nohup emacs &'
$ ps -ef | grep emacs | grep -v grep
susam 22229 1 0 14:02 pts/0 00:00:00 emacs
susam 22238 1 2 14:03 pts/0 00:00:00 emacs
$ ps -ef | head -n 2
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Dec29 ? 00:00:01 /sbin/init
In the second experiment, the parent of the emacs process is the init process, to it continues to run successfully even after the shell or terminal exits.
To summarize, yes, we can use nohup in the startup script and make it POSIX compliant.