How to run a Python script in the background even after I logout SSH?


Question

I have Python script bgservice.py and I want it to run all the time, because it is part of the web service I build. How can I make it run continuously even after I logout SSH?

1
101
6/4/2010 3:39:39 PM

Accepted Answer

Run nohup python bgservice.py & to get the script to ignore the hangup signal and keep running. Output will be put in nohup.out.

Ideally, you'd run your script with something like supervise so that it can be restarted if (when) it dies.

191
6/4/2010 3:41:50 PM

If you've already started the process, and don't want to kill it and restart under nohup, you can send it to the background, then disown it.

Ctrl+Z (suspend the process)

bg (restart the process in the background

disown %1 (assuming this is job #1, use jobs to determine)


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon