Automatically disown application when running it from a terminal

background-processdisownterminal

How do you automatically disown an application after you have started it from a terminal?

For example: if you start a terminal and run firefox the application will start, but when you then close the terminal firefox will close as well. To avoid unintentionally closing applications that have been started from a terminal, one can first put them in the background with the ampersant: firefox & which also restores the ability to use that terminal's prompt.
Next, you can disown the application from that same terminal using the process ID (PID) of the application, see this example below:

$ firefox & 
$ ps | grep firefox
14917 pts/6    00:00:00 firefox
$ disown 14917

The application now runs independently from the terminal you are using, and closing the terminal will no longer terminate the application.

But how can you do this automatically each time you start an application?

Best Answer

The simplest way is to execute:

daemon firefox

so you can continue using/closing the terminal itself

Related Question