Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I often execute GUI programs, such as firefox and evince from shell. If I type "firefox &", firefox is considered as a bash job, so "fg" will bring it to foreground and "hang" the shell. This becomes annoying when I have some background jobs such as vim already running.

What I want is to launch firefox and dis-associate it with bash. Consider the following ideal case with my imaginary runbg:

$ vim foo.tex
ctrl+z and vim is job 1
$ pdflatex foo
$ runbg evince foo.pdf
evince runs in background and I get me bash prompt back
$ fg
vim goes foreground

Is there any way to do this using existing program? If no, I will write my own runbg.

share|improve this question
    
nohup and disown are not what you're after? –  slhck Jun 11 '12 at 9:40
    
Note that you can specify the job that you want to move to the foreground i.e. fg %1. –  cYrus Jun 11 '12 at 15:58
add comment

1 Answer

Do this:

bash$ firefox &
bash$ disown

Bash has now forgotten about the background job you just created.

share|improve this answer
    
This is exactly what I want. Thanks. –  Wu Yongzheng Jun 12 '12 at 2:27
    
After using it for sometime, I couldn't get used to it. The problem is I have to specify the job number. disown with no argument doesn't detach the previous background job, but the "current job", which I found strangely defined. –  Wu Yongzheng Jun 12 '12 at 7:39
    
I believe the most-recently backgrounded job is always the current job, unless you change the current job before you type disown. –  Fran Jun 12 '12 at 14:50
    
Hi Fran, try this. 1. vim foo; 2. gedit bar &; 3. disown; 4. fg. Step 3 disowns vim and step 4 brings gedit to foreground. After reading bash manual, I still don't know why bash considers vim as the current job in step 3. –  Wu Yongzheng Jun 18 '12 at 9:22
add comment

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.