1

How can I run a python script in ubuntu background? I tried to use '&', for example:

python3 test.py &

but when I close the terminal, this process seems to be closed as well because I can't get any update logs from this test script any more.

Marco Mei
  • 97
  • 2
  • 10
  • Add `nohup` http://stackoverflow.com/questions/32784462/how-to-run-multiple-php-scripts-in-background-on-ubuntu – Serge Apr 21 '17 at 01:10
  • read this answer [http://stackoverflow.com/questions/2975624/how-to-run-a-python-script-in-the-background-even-after-i-logout-ssh](http://stackoverflow.com/questions/2975624/how-to-run-a-python-script-in-the-background-even-after-i-logout-ssh) – minji Apr 21 '17 at 01:12

2 Answers2

3

You can use setsid. In your case by running:

setsid python test.py

Or, as mentioned in the comments, you can use nohup.

nohup python test.py

You can see the difference between them in this answer: What's the difference between nohup and a daemon?

Community
  • 1
  • 1
eli-bd
  • 1,533
  • 2
  • 17
  • 35
1

I think you're looking for the nohup command as Serge mentioned.

This answer looks like what you want

Community
  • 1
  • 1
ajthyng
  • 1,245
  • 1
  • 12
  • 18