Running programs in the background from terminal
I've recently come to like setsid
. It starts off looking like you're just running something from the terminal but you can disconnect (close the terminal) and it just keeps going.
This is because the command actually forks out and while the input comes through to the current terminal, it's owned by a completely different parent (that remains alive after you close the terminal).
An example:
setsid gnome-calculator
I'm also quite partial to disown
which can be used to separate a process from the current tree. You use it in conjunction with the backgrounding ampersand:
gnome-calculator & disown
I also just learnt about spawning subshells with parenthesis. This simple method works:
(gnome-calculator &)
And of course there's nohup
as you mentioned. I'm not wild about nohup
because it has a tendency to write to ~/nohup.out
without me asking it to. If you rely on that, it might be for you.
nohup gnome-calculator
And for the longer-term processes, there are things like screen
and other virtual terminal-muxers that keep sessions alive between connections. These probably don't really apply to you because you just want temporary access to the terminal output, but if you wanted to go back some time later and view the latest terminal activity, screen would probably be your best choice.
The internet is full of screen
tutorials but here's a simple quick-start:
- http://thingsilearned.com/2009/05/26/gnu-screen-super-basic-tutorial/
Here's the two ways I'd go with. Firstly, not running it from a terminal; hit Alt+F2 to open the run dialog, and run it from there (without &).
From a terminal, run
nm-applet &
But do NOT close the terminal yourself. That is, do not hit the X-button to close, and do not use File -> Exit from its menubar. If you close the terminal that way, it will send a HUP (Hang UP) signal to the bash running within, which in turn will send the HUP signal to all its children (which is why nohup works in this case).
Instead, exit the shell by running exit
or hitting Ctrl+D. bash will then disown its children, then exit, leaving the background processes still running. And when bash exits, the terminal has lost its child process, so it will close too.
Doing it all at once:
nm-applet & exit
As you pointed out, you can run
nohup nm-applet &
to ignore the end signal when closing the terminal. No problem with that.