How can I keep a command I started from the shell running if I logout from the shell?

Which methods exist to keep a command that was started from shell on running after logging out from from shell?

4 Answers

  • 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 Install screen, dtach Install dtach and nohup.

    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

2

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 &
1

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 &

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like