1

I have a program that I normally run as so:

sudo /home/pi/code/./main 12345

where 12345 is just a input. This code runs infinitely until I forcefully stop it.

However, I want my pi to do this automatically when turned on. It already automatically logs in so I tried to put the above line inside /etc/rc.local

unfortunately, when I restarted, the pi is stuck on the raspberry graphic(I'm in command line mode). Obviously this is from my program. What should I do so this program can run without obstructing everything else?

Luckily I had a backup so I can try again, but this time I'd like to do it right.

2 Answers 2

5

have you tried to add an ampersand to your command to allow it to run in the background?

sudo /home/pi/code/./main 12345 &
7
  • no, would that be obstructive even in the background?
    – mugetsu
    Commented Sep 9, 2013 at 23:43
  • unless you put an ampersand, your pi is stuck wherever you call you program from, until it's finished. please, try and see?
    – lenik
    Commented Sep 9, 2013 at 23:46
  • I just did, and the function no longer seems to be working. But, the boot problem is gone!
    – mugetsu
    Commented Sep 9, 2013 at 23:55
  • well, now you have to fix your program =)
    – lenik
    Commented Sep 10, 2013 at 0:42
  • 1
    sudo expects the password, that may be the reason it won't work from the batch file. use something like: $echo <password> | sudo -S <command>
    – lenik
    Commented Sep 10, 2013 at 0:55
7

First, running sudo su or sudo on boot is useless, as you are already running as root. Only if you want to run as a different user you should use the su - user -c "command". You may doing this to setup the login root ENVIRONMENT, but then the command is su - -c "command"

As for running the command, use

nohup /home/pi/code/./main 12345 & 

The app is probably trying to grab a tty and in the rc.local you have none. nohup might solve it.

If still don't work, try this one (you may need to install screen: apt-get install screen ):

screen -d -m /home/pi/code/./main 12345

screen will emulate a full terminal and run it i background. You can see it later with screen -x as the same user as the main process (root in this case).

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.