2

How do I fork a process that doesn't die when shell exits? talks about "double forking":

  • Double-fork():

    (emacs &)
    

    Commands inside braces ( ) are run in a separate shell process.

Could you explain why that would make any difference compared to a simple emacs &. What would be the point of running it in a subshell environment in the first place?

Seth
  • 9,393

1 Answers1

1

Could you explain why that would make any difference compared to a simple emacs &.

(emacs &) runs a subshell which then runs emacs & inside it, which means that its stdin, stdout, and stderr are tied to the subshell instead. It becomes double-forked and will survive the initial shell (where (emacs &) was run) dying. Running only emacs & will keep the stdin, stdout, and stderr tied to the initial shell.

emacs is actually a bad example for this because the GUI version will not care that it lost its stdin, stdout, and stderr. You can try with (ls -R / &); exit and then grep for it to see that it is still running. Edits welcome for a better example than ls.

What would be the point of running it in a subshell environment in the first place?

To detach it completely from the initial shell (see above).