14

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

4 Answers 4

12
  • 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
  • doesnt adding an & at the end of the command work too? Dec 24, 2010 at 10:35
  • 2
    @Kaustubh-P using & is often a good habbit to close terminals via the 'exit' command, not hitting the X close button.& makes the command run in thebackground.But if the parent shell closes. that can still force the background programs to exit.
    – karthick87
    Dec 24, 2010 at 10:40
6

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.

5

Use the nohup command like this:

nohup gedit /home/user/file.txt &
1
  • How to even remove nohup: ignoring input and redirecting stderr to stdout
    – Amruth A
    Jun 19, 2019 at 12:41
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 &

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .