Run python script in the background

Create a new file, named script.sh.

# Make your file executable by using chmod
chmod +x script.sh

 

 Add the following content into your file, where script.py represents your python file.

#!/bin/bash
nohup python script.py  &

 

Execute your file

./script.sh

 

Check if your script is running:

ps ax | grep script.py

 

Stop your script by using pkill

pkill -f script.py -9

 

Top