How to Prevent a Background Process from Being Stopped After Closing Ssh Client in Linux

How to prevent a background process from being stopped after closing SSH client in Linux

Check out the "nohup" program.

Prevent an already running background process from being stopped after closing SSH client

use

commandtoexecute &> /dev/null &

it will run your process in the background, and prints all output to /dev/null.

Replace /dev/null with another file to see the output.

e.g.
commandtoexecute &> /tmp/file1 &

use
tail -f /tmp/file1 to attach to output again

You can also redirect stdin, see this
http://www.tuxfiles.org/linuxhelp/iodirection.html

If you want to detatch from a process that is allready running. Use
disown <pid>
where pid is your process id.

You could also change the terminal to another terminal:

  1. start a screen
  2. get pid of your process
  3. run reptyr <pid>
  4. detach using CTRL+A+D

reptyr: https://serverfault.com/a/284795

How to not have my process dies out when my linux session goes time out

You have to start the process in detached mode by:

nohup python main.py 2>&1 1>/dev/null &

Keep Go script running on Linux server after ssh connection is closed

There are mainly three options here, one is to use the nohup command, the other is to use the screen command, and the last is the upgraded version of byobu of screen. After reading these three commands, I actually prefer to use the byobu command, because the byobu command is more powerful, an upgraded version of screen, and the interface is more friendly.

background process is always Stopped

Try running with nohup. You can analyse the nohup.out log if it still stops.

nohup script.sh


Related Topics



Leave a reply



Submit