Im new to linux and the pi . Im stuck with this situation where Iv been trying to run a simple LED blinking C code as a test , so that it will be executed during startup

Code works fine when its executed from its folder indicating its a working code What I have done so far is

1. I put direction to the folder and command to run code in /etc/rc.local ie

cd home/pi/C_Codes

and then run sudo ./blink.c

It work on 1st boot, but 2nd boot onwards it crashes and fails, but the pi does boot up, without any output(blinking of LED)

2. After creating new script(copy paste) as


I would run update-rc.d blink_startup.c enable

it gives error saying

blink_startup.c Default - Start contains no run levels

3. After running in root terminal, i gave chmod 755 /etc/init.d/blink_startup.c to check program and then gave update to make it work on booting - update-rc.d blink_startup.c defaults it gives the error - insserv: warning:script 'K01blink_startup.c' missing LSB tags and overrides

If someone could assist me and guide me through the situation to tackle this, would really appreciate it

Good Day

  • 1
    C is a compiled language. I.e. the source code is compiled into an executable and the executable is run. A file with name blink.c suggests a C source file, not an executable file. What does blink.c contain?
    – joan
    Dec 19, 2014 at 13:31
  • @joan already mentioned the fact that the c-file (that is source code not an executable script) needs compiling first. On the other hand the scripts in the init.d-framework are something completely separate.
    – Ghanima
    Dec 19, 2014 at 13:36
  • 2
    Couldnt you just have cron run your script on @reboot
    – BluGeni
    Dec 19, 2014 at 14:18

2 Answers 2

  1. command to run code in /etc/rc.local

    Three things to remember when putting commands in rc.local:

    • Don't use sudo, because the script is run as root anyway.

    • Unless the command exits quickly, it must fork to the background. This is accomplished by adding & to the end:

      mycommand &
    • $PATH may not be set. This is a list of directories where the shell searches for commands. To be sure, you need to either do something like this at the beginning of the script:

       export PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin

    Or use absolute paths with all commands. You can find these normally with which.

  2. I would run update-rc.d blink_startup.c enable

    As a few people have pointed out, conventionally a .c file is source code. If this is a shell script in /etc/init.d, it should be suffixed with .sh. It also must conform to the rules described in /etc/init.d/README, which is why you are getting an error.

  3. See #2, re: the rules this must conform to.

  • is there a way to test changes to rc.local so you can see if you have set up your commands correctly? Can you run rc.local to see if there are errors from a ssh command line?
    – Roger
    Mar 10, 2015 at 20:05
  • @Roger Presuming your commands have some kind of output, you can do something like myapp &> /tmp/myapp.log &. The &> redirects standard output and standard error; the final & ensures it forks to background (which it needs to unless it is going to exit quickly -- I've updated this answer re that). If your commands won't produce any output, but exit quickly, don't fork (no final &), and you can check the exit status with the shell's $? variable. If your commands don't produce any output but are persist or don't vary their exit status, find whoever wrote them and tell them off ;)
    – goldilocks
    Mar 10, 2015 at 20:18
  • Sorry, not sure I quite understand you (brand new to Pi and to linux). The app I am attempting to run takes command line arguments. Won't it just try to consume what you suggested? Should start my own question instead of trying to add on here?
    – Roger
    Mar 10, 2015 at 20:27
  • The arguments should go before the output redirection (&> log), and the fork (&) should be at the very end. WRT general linux questions, Unix & Linux is a more appropriate place to ask about things like this. This question was really off-topic in the first place, since it does not involve the pi in a relevant way (the particular hardware doesn't matter). Unless you see a definite connection to the hardware, assume you have a general linux question.
    – goldilocks
    Mar 10, 2015 at 21:08
  • Tried what you suggested, and did not get anything. Agree I am off topic, moving here: unix.stackexchange.com/questions/189411/…
    – Roger
    Mar 11, 2015 at 0:09

On recent versions of Raspbian, you can use a cron job for this.

Run crontab -e and select your favorite editor when prompted, then add the following to the bottom of the file:

@reboot /path/to/executable

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.