Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
How about using XTERM instead of the Normal Terminal –  Tasos Mar 25 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. –  Mark Mar 25 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 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 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 at 5:06

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
    
So, a more concise way might be: sublime-text ~/.zshrc&; disown –  Mark Mar 26 at 16:03
    
Yes. sublime-text ~/.zshrc & disown. This way it just works fine for me. –  cgty Mar 26 at 16:36

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

share|improve this answer
    
This prints an annoying message, "nohup: ignoring input and appending output to ‘nohup.out’" –  Mark Mar 26 at 16:00

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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