Ubuntu: Run Program in Background Which Survive Terminal Close

July 19, 2019

Run program in background

nohup COMMAND &

Run Python in background

nohup python FILE.py PARAM &

Pipe output and stderr to log file

nohup COMMAND > /DIR/LOGFILE.log 2>&1 &

Save Process ID

nohup COMMAND > /DIR/LOGFILE.log 2>&1 &
echo $! > /DIR/PID.txt

Check Process Status

ps -p `cat /DIR/PID.txt`

Kill Process

kill -9 `cat /DIR/PID.txt`
rm /DIR/PID.txt
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.