News How to Run a Script at Boot on Raspberry Pi

bit_user

Titan
Ambassador
In fairness, I didn't know crontab had @reboot. However, I wonder if it can distinguish between a real reboot and the cron daemon simply getting restarted. Probably doesn't matter... just a thought.

What if you want to stop your autorunning script after your Raspberry Pi has booted? If your script has already completed running, it will be gone from memory but if it’s designed to do something continuously, you’ll need to search for and kill the task.
That's when you really ought to consider making it a service. See:
Anyway, on killing a process...
1. Search for your script by using the ps aux command and putting the name of your script (or at least a partial name) after grep.

...

2. Kill each process number using the sudo kill -9 command.

You can do it in just one step, using the killall command. Just be sure your script is named uniquely, and that you really want to kill all instances of it.


Probably should also mention something about signals and how it's sometimes with trying SIGINT or SIGTERM, before reaching for SIGKILL.