Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-10-2010, 11:43 AM   #1
Registered: Feb 2010
Posts: 181

Rep: Reputation: 16
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..............) ?
Old 03-10-2010, 12:20 PM   #2
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
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.

Last edited by rweaver; 03-10-2010 at 12:23 PM.
Old 03-10-2010, 12:51 PM   #3
Registered: Feb 2010
Posts: 181

Original Poster
Rep: Reputation: 16
yes i know.but can i do this from c++ code,or manualy copy the program to /etc/init.d ?
Old 03-10-2010, 01:17 PM   #4
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
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.
Old 03-11-2010, 04:12 AM   #5
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,412

Rep: Reputation: 416Reputation: 416Reputation: 416Reputation: 416Reputation: 416

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

@reboot /bin/my_prog


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to autorun a CD or Program golfadict Linux - Newbie 5 11-06-2009 03:22 PM
HOWTO autorun a program on start up? kodaku Linux - Software 6 08-12-2004 10:40 PM
AutoRun Program in XWindows zael Linux - Newbie 3 02-09-2004 07:49 AM
autorun application program on hotplug kevinatkins Linux - Software 0 02-08-2004 08:44 AM
autorun a program in tty3 LynX Linux - Newbie 2 11-09-2002 05:07 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration