I have two Python 2.7 programs. When I boot the Raspberry Pi I want to run that programs automatically. I also want to very 30 minutes close that programs and run them again. I imagine that the best option for that is Cron, but if I run again the Python programs are going to close the previous ones? Can anyone help me to program this project?

Thanks in advance.

2 Answers 2


Use crontab as mentioned by Conor. You can run as many scripts as you want and they won't affect each other. I have these setup on all my Pis to run bash and python scripts. It looks a bit intimidating at first as crontab generates a template but you can erase all of it and use the configuration below.

$ crontab -e

## Crontab Configuration ##
29,59 * * * * (bash -c 'pkill -f scriptName.py') #This will kill your task on the 29th and 59th minute of every hour.
0,30 * * * * (bash -c 'cd ~/path/to/script && python scriptName.py') #This will run your task on the 0th and 30th minute of every hour.

Use cron to run a script that first closes any existing instance of the program, and then starts a new one. "killall" works well to kill any existing instances, usually

  • Yes, I will try it, but killall was just what I was looking for. Thanks.
    – Andermutu
    Sep 14, 2017 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.