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. Usedisown <pid>
where pid is your process id.
You could also change the terminal to another terminal:
- start a screen
- get pid of your process
- run
reptyr <pid>
- 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
Format and Then Convert Txt to CSV Using Shell Script and Awk
How to Redirect Output to a File and Stdout
How to Change the Root Directory of an Apache Server
Retaining File Permissions With Git
More Elegant "Ps Aux | Grep -V Grep"
Linux: Copy and Create Destination Dir If It Does Not Exist
Register File Extensions/Mime Types in Linux
Contiguous Physical Memory from Userspace
Run Several Jobs Parallelly and Efficiently
How to Turn Off Echo While Executing a Shell Script Linux
Iterate Over a List of Files With Spaces
How to Declare 2D Array in Bash
How to Parse a CSV File in Bash
How to Access Physical Addresses from User Space in Linux
How to Copy Commits from One Git Repo to Another