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:
- https://thingsilearned.com/things/gnu-screen-super-basic-tutorial/
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:
- https://thingsilearned.com/things/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
background process - Run a command without making me wait - Unix & Linux Stack Exchange
bash - How can I put the current running linux process in background? - Stack Overflow
Running a terminal command in the background
Terminal: how do I run a command, send it to the background and return to the shell without killing the process.
How do I run a command in the background and log its output?
What happens to background job output if I close the terminal?
Can I run multiple commands in the background at the same time?
Videos
When I launch the proot-distro I've installed, I need to launch the vncserver, but it starts printing the output to the screen, instead of saying "Starting vncserver, sending program to work in the background. Here's your shell again. :)" The same applies for other software like Firefox and other desktop software.
I know about Ctrl+Z but I don't want to suspend/pause the software, it's not usable when paused.
Before running the command, you can append & to the command line to run in the background:
long-running-command &
After starting a command, you can press CtrlZ to suspend it, and then bg to put it in the background:
long-running-command
[Ctrl+Z]
bg
This is the favorite of all since apart of sending the process into the background you don't have to worry about the text output dirtying your terminal:
nohup command &
This not only runs the process in background, also generates a log (called nohup.out in the current directory, if that's not possible, your home directory) and if you close/logout the current shell the process is not killed by preventing the child proccess from recieving the parent signals when killed (ie. logging out, by SIGHUP to the parent, or closing the current shell).
There's other called disown but that's rather a extension of other answers rather that a method in itself:
command & # our program is in background
disown # now it detached itself of the shell, you can do whatever you want
These commands do not allows you to recover easily the process outputs unless you use a hackish way to get it done.
There are different ways to run a terminal program and continue using the terminal:
- You can open another terminal tab (right-click, then select "Open New Tab").
- You can append
&to the command you run. Be aware that you will not see text output to the terminal, such as error messages. - You can type Ctrl-Z and then run
bg. This has the same effect as runningcommand & - You can run
nohup command &and then press enter. (Thanks to ccpizza, see comments below.)
However, pressing Alt-F2 and then running your command from the GUI is usually considered best practice - there is no terminal at all!
Note that when using & (not nohup), closing the terminal will still terminate the application unless you run disown afterwards.
EDIT: It looks like using nohup will sometimes leave little droppings in your home folder. What would normally have been logged to the terminal is apparently saved to a file in ~/.
~~
A simple way to run a program in the background is program-name & disown, which will drop you to a terminal which can be closed without killing the process.
You can use setsid to run program in a new session with addition to &>/dev/null so you will not receive any log messages.
So it would be like
setsid program-name &>/dev/null
How to run a command in the background without the terminal open? Example: i want to run watch - - interval 300 chown - R directory * but I don't want to keep the terminal or open the whole time it's running. How do I go about this?