How to configure startup program in RaspberryPi

The Raspberry Pi is a tiny and affordable computer that you can use to learn programming through fun, practical projects.

This article explains the steps to add a program to run in the startup.

Step1: Open the file '/etc/rc.local'

#nano /etc/rc.local

Step2: Add the program or script that need to be run in the start up. For example,

python /home/pi/myscript.py

Be sure to leave the line exit 0 at the end, then save the file and exit.

If your program runs continuously (runs an infinite loop) or is likely not to exit, you must be sure to fork the process by adding an ampersand (“&”) to the end of the command.

python /home/pi/myscript.py &

If you add a script into /etc/rc.local, it is added to the boot sequence. If your code gets stuck then the boot sequence cannot proceed. So be careful as to which code you are trying to run at boot and test the code a couple of times.

 

Leave a Reply

Your email address will not be published. Required fields are marked *