Ubuntu: Run Program in Background Which Survive Terminal Close

Jul 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

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.