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?
When you want a process to continue running even after you log off a Linux system, you have a couple options. One of them is to use the disown command. It tells your shell to refrain from sending a HUP (hangup) signal to the process when you log off. So, the process continues running.
When you log in to the server, the terminal session won't automatically close. Instead, the configuration file will keep sending the alive signal after the specific interval set in the configuration file to keep the terminal session alive.
Running shell command or script in background using nohup command. Another way you can run a command in the background is using the nohup command. The nohup command, short for no hang up, is a command that keeps a process running even after exiting the shell.
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
.
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..
You should try using nohup
and running it in the background:
nohup sleep 3600 &
I would try the program screen.
Start in the background:
./long_running_process options &
And disown the job before you log out:
disown
You want nohup. See http://nixcraft.com/linux-software/313-ssh-nohup-connection.html
You could use screen
, detach and reattach
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With