2

Sorry for the lame question, I faced VDS for the first time in my life. I've set everything up, installed all python modules the app needed and after I run my script like

python test.py

it works just ok, but after I close my ssh window that i used for remote connect to my VDS - the script doesn't work anymore.

How to run my test.py to make it work 24\7?

1 Answers1

3

You can use the nohup command:

nohup python test.py &

This will continue to run the command even after you close your ssh session. nohup catches the SIGHUP signal when the controlling terminal process dies to ensure the command continues to run.

Simply using python test.py & might also work if your shell ignores SIGHUP. In that case, your python process would be re-parented to the init process and continue to run. But this relies on the shell.

For example, bash has an option huponexit - when it's off, the re-parenting would happen; when it's on, SIGHUP will be sent to the background processes. So nohup is the way to go.

P.P
  • 1,121