LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   autorun program in c++ (https://www.linuxquestions.org/questions/programming-9/autorun-program-in-c-794463/)

vbx_wx 03-10-2010 10:43 AM

autorun program in c++
 
With what functions i can write my program in /etc/init.d with c++ to start every time the computer starts ? (like in windows with RegOpenKey,RegSetValueEx..............) ?

rweaver 03-10-2010 11:20 AM

I'm sorry, this is pretty unclear. Linux does not use a registry like windows, typically starting a linux daemon is as easy as making an init script for the actual executable and linking it to the correct runtimes which is a process entirely done outside c++. For example how apache starts in your distribution (cat /etc/init.d/httpd or /etc/init.d/apache2 in all likelihood) you can compare that to sshd or mysql to get an idea of what is required and optional.

vbx_wx 03-10-2010 11:51 AM

yes i know.but can i do this from c++ code,or manualy copy the program to /etc/init.d ?

sarin 03-10-2010 12:17 PM

If you just want to start something at boot-up, use rc.local. You can compile your program and place the binary in, say, /bin. Then edit /etc/rc.local and add a line like this:

/bin/my_prog &

Remember to put the '&'. Else, your machine may hang while booting.

Guttorm 03-11-2010 03:12 AM

Hi

Another easy way to run something at reboot is to use cron. Put something like this in your crontab:

@reboot /bin/my_prog


All times are GMT -5. The time now is 12:04 PM.