Auto running applications in the GUI

See here

Auto running terminal applications (non GUI)

First ensure your program is executable by finding it in the file manager.  Right click on the file and select properties.  Select the permissions tab, check the ‘Make the file executable’ box and press OK.  Or from the command line use:

sudo chmod +x /home/pi/projects/my_project.a

Or using a different tool set its chmod to 755 (rwxr-xr-x).  It doesn't matter if the user is root.

Doesn't work?

We've found that when copying a new file to the rpi using WinSCP, changing its properties to 755 and verifying all is OK that if we kill the power and power up again the executable doesn't run.  However if we use sudo reboot at the command line it works as it should.  It seems there is some sort of caching action going on so after doing this use sudo reboot the first time rather than cycling the power!

You can setup the auto run using a script (see here), or you can do it directly by editing the rc.local file:

sudo nano /etc/rc.local


After the initial comments (lines beginning with '#') add the following lines:

# Auto run our application
sudo /home/pi/projects/my_project.a &

"sudo" assumes you want your application run with root user privileges (remove if not) and the "&" says do it in the background.

Save it by pressing Ctrl+X, " Y", ENTER

Re-boot your RPi and it will run.

To kill the program

If you need to kill your program running in the background you can use this

sudo killall my_project.a
If the program has auto run but is in a loop and you can't kill it!

Often the keyboard interface to the RPi is still working even though you may not see what you type due to your program writing to the screen in the background.  Try typing your username and then password as you normally would at login and then the "sudo killall" above and it may well kill it

Running multiple things and also programs as a non root user

You can use brackets around multiple commands each separated by a ';' followed by the '&' to run the set of commands all in the background.

If you use the '&' you can also run multiple lines as each is run in the background.

Finally, by default rc.local runs as the root user.  You can change to a different user using su – USERNAME -c before the command and surrounding it with quotes.

In the example below the following occurs:

After a 2 second pause my_project.a us run in the background.

After a 5 second delay VLC is started to stream the raspberry pi video camera.  VLC won't run as the root user so su -c is used to make it run as the user "pi"

#Auto run our application
(sleep 2;sudo /home/pi/projects/my_project/my_project.a)&
#Auto run VLC video streaming
(sleep 5;su - pi -c "raspivid -o - -t 0 -n -w 640 -h 480 -fps 15 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264")&


We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.