How can I keep a command I started from the shell running if I logout from the shell?
-
To put the application into the background, use
&
:command &
-
If you wish to close the terminal, and keep the application running, you can use several options:
screen
,dtach
andnohup
.nohup command &
Screen is helpful as you can re-start a session and dtach is fun as well.
-
Look at the following links for more informations
- Screen
- Dtach
A useful (bash?) command is disown
. the nice thing about it is that it works for an already running job (by the way, you disown jobs, not processes, so you need to do a ctrl-Z, bg
before running disown on your job. For example, imagine yourself doing the following:
local % ssh some.where.com
remote % verylongscript.sh
Now you realize that you need to go but don't want the script to be killed upon exiting, so you
ctrl-Z
remote % bg
remote % disown
remote % exit
local %
Now, on remote
, your script is still running.
Use the nohup command like this:
nohup gedit /home/user/file.txt &
I use
nohup mycommand &
For example to bring up a VirtualBox virtual server I type the following in a remote shell (which I close then):
nohup VBoxHeadless --startvm "myvm" --vrdp=off &