3

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>.

7
  • How about using XTERM instead of the Normal Terminal
    – Tasos
    Mar 25, 2014 at 22:55
  • @Tasos: You're going to have to elaborate on that. I've only got a vague idea of what xterm is, and I don't know how it solves this particular problem.
    – mpen
    Mar 25, 2014 at 23:46
  • 1
    Its an alternative to a terminal. Its comes with Ubuntu and does the same stuff as a Normal terminal. Doesn't Sublime come with an Icon anyway you can start it that way or do you actually need the Terminal for some reason i didn't understand?
    – Tasos
    Mar 25, 2014 at 23:58
  • Could you please explain how/why is it more convenient to use sublime-text /path/to/my/file <super-secret-character-that-disconnects-the-app-not-just-puts-it-in-the-bg> from a terminal than double-clicking (or right-click, open with) the filename in a file manager?
    – DK Bose
    Mar 26, 2014 at 1:53
  • 1
    @DKBose I too launch my editor mostly by command line; I can use tab completion, shell variables, gobbling for multiple files, find tricks... Infinitely faster than browsing the graphical file manager. For example gvim -p convert*.[ch]...
    – Rmano
    Mar 26, 2014 at 5:06

3 Answers 3

4

You can use disown command to detach background processes from the terminal.

If you have only one running background job, you can simply use

disown

and the owner of this background process will no longer be the terminal, so it will keep running even after the terminal is closed.

2
  • So, a more concise way might be: sublime-text ~/.zshrc&; disown
    – mpen
    Mar 26, 2014 at 16:03
  • Yes. sublime-text ~/.zshrc & disown. This way it just works fine for me.
    – cgty
    Mar 26, 2014 at 16:36
3

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, use disown % <job number>. Below is an example of how to disown xload.

jobs
[1]+  Stopped                 man man
[2]-  Running                 xload &
[3]-  Running                 xeyes &

disown %2

To prevent the problem from the start, use the nohup command. So I would add this line to your .bashrc file:

alias sublime-text='nohup sublime-text'  

Then type sublime-text < filename> &.

1
  • This prints an annoying message, "nohup: ignoring input and appending output to ‘nohup.out’"
    – mpen
    Mar 26, 2014 at 16:00
2

nohup gedit &. Now you can just press enter to continue entering commands and stuff and if you close the terminal, gedit will stay open.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.