Process id dismiss when ssh connect again

December 21, 2017 1.5k views
Python Frameworks Ubuntu Debian Development

In order to execute a task background, I use nohup command.

 # nohup python &

Everything works well but when I close ssh connection and connect it again, I find the process id does not exist.The python task sends a request to an api every 20 minutes.From the api server console, I find the process still works.However from ps command I can not find the process id

1 Answer

It’s possible that the program has crashed. I would recommend using screen instead of nohup. You can install it by running

sudo apt-get install screen

Then, you can start a session by running screen. This will launch a new bash process that you can run python in. First, enable logging in order to identify the issue by pressing Ctrl-a, H. Run your program, and press Ctrl-a, d to detach from the session, which will keep it running in the background. You can now disconnect from your Droplet and the screen session will keep running. Keep an eye on the log file and see if it has any information if the process quits again.

Have another answer? Share your knowledge.