49
18
I run a lot of programs in Ubuntu from the terminal, but I would like to be able to continue using the terminal after I have a program open. How can I put the programs in the background so that I don't have to open another window?
49
18
I run a lot of programs in Ubuntu from the terminal, but I would like to be able to continue using the terminal after I have a program open. How can I put the programs in the background so that I don't have to open another window?
64
There are different ways to run a terminal program and continue using the terminal:
&
to the command you run. Be aware that you will not see text output to the terminal, such as error messages.bg
. This has the same effect as running command &
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.
8
This works only until you close the terminal window, once you close the window the program will terminate – kurdtpage – 2018-07-06T01:20:53.940
6
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
Cool. It must keep process running when user logout and current session closed. – Mikhail Moskalev – 2019-03-07T15:40:38.177
2
Using screen
command, you can open multiple terminal sessions using a single window
apt-get install screen (On Debian based Systems)
yum install screen (On RedHat based Systems)
screen
(start new screen)
[Your command]
Ctrl+A d
to leave screen
... and so on
0
You can run it in a virtual terminal like tmux
(or screen
but I heard it's not maintained anymore)
# This ataches your terminal to a virtual terminal
tmux
run_your_command
# This detaches your virtual terminal (previous command can be running)
CTRL-b d
run_other_commands # on your terminal
# re-attach the virtual terminal to see the status of run_your_command
tmux a
tmux
can do a lot more, like :
https://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/
program-name & disown
is a nice solution – Doctor Henry – 2019-08-03T12:34:18.2174To prevent killing the child process after the terminal is closed you can start your app as
nohup firefox&
. – ccpizza – 2012-12-03T22:25:44.220Cool! I didn't know that (but upon experimentation, the terminal is still "blocked")! – WindowsEscapist – 2012-12-03T23:35:40.257
it is not 'blocked', it only 'looks' blocked, if you type enter once you will get a prompt. – ccpizza – 2012-12-04T21:07:17.027
Ah, I didn't notice that before. – WindowsEscapist – 2012-12-05T00:06:32.543