How to make a program continue to run after log out from ssh?

LinuxBashSsh

Linux Problem Overview


> Possible Duplicate:
> Prevent a background process from being stopped after closing SSH client

I have a program that takes a lot of time to finish. It is running as root over ssh.
I want it to continue to run after I logout,is this possible and how would I achieve this?

Linux Solutions


Solution 1 - Linux

Assuming that you have a program running in the foreground, press ctrl-Z, then:

[1]+  Stopped                 myprogram
$ disown -h %1
$ bg 1
[1]+ myprogram &
$ logout

If there is only one job, then you don't need to specify the job number. Just use disown -h and bg.

Explanation of the above steps:

You press ctrl-Z. The system suspends the running program, displays a job number and a "Stopped" message and returns you to a bash prompt.

You type the disown -h %1 command (here, I've used a 1, but you'd use the job number that was displayed in the Stopped message) which marks the job so it ignores the SIGHUP signal (it will not be stopped by logging out).

Next, type the bg command using the same job number; this resumes the running of the program in the background and a message is displayed confirming that.

You can now log out and it will continue running..

Solution 2 - Linux

You should try using nohup and running it in the background:

nohup sleep 3600 &

Solution 3 - Linux

I would try the program screen.

Solution 4 - Linux

Start in the background:

./long_running_process options &

And disown the job before you log out:

disown

Solution 5 - Linux

Solution 6 - Linux

You could use screen, detach and reattach

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionomgView Question on Stackoverflow
Solution 1 - LinuxDennis WilliamsonView Answer on Stackoverflow
Solution 2 - LinuxpaxdiabloView Answer on Stackoverflow
Solution 3 - LinuxJanuszView Answer on Stackoverflow
Solution 4 - LinuxdiciuView Answer on Stackoverflow
Solution 5 - LinuxMatthew FlaschenView Answer on Stackoverflow
Solution 6 - LinuxbrndnmgView Answer on Stackoverflow