I can run Sublime, for example, in the background by typing
sublime-text &
The &
puts it into the background so that I can continue to run commands in my terminal. Alternatively, I can run
sublime-text
Which locks up my terminal. If I then press Ctrl+Z it "suspends" the application which essentially freezes it (it will eventually turn gray). Typing bg
moves it into the background and unlocks the terminal.
In any case, if I exit the terminal or type fg
and then Ctrl+C, the application will close.
How do I "disconnect" the GUI application from the terminal so that it will not close should I close the terminal or press Ctrl+C? In other words, I would like to use the terminal as a launcher, which is particularly convenient when I want to open a specific file: e.g., sublime-text /path/to/my/file <super-secret-character-that-disconnects-the-app-not-just-puts-it-in-the-bg>
.
You can use
disown
command to detach background processes from the terminal.If you have only one running background job, you can simply use
and the owner of this background process will no longer be the terminal, so it will keep running even after the terminal is closed.
Under bash, use the disown command to fix an existing process. To get the list of background processes attached to the current shell, use the
jobs
command. Then to disown the desired process, usedisown % <job number>
. Below is an example of how to disown xload.To prevent the problem from the start, use the nohup command. So I would add this line to your .bashrc file:
Then type
sublime-text < filename> &
.nohup gedit &
. Now you can just press enter to continue entering commands and stuff and if you close the terminal, gedit will stay open.