Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a C program which I want to run as a daemon. How do I install it so it will run as a daemon on CentOS? Someone said to use @reboot, and some said to put it in /etc/rc.d/rc.local. Which is the right way?

share|improve this question
Note that daemon has a special meaning, daemon listens for input for the program control data over the network listener interface is said to be daemon, generally. However, any program which runs in background interface silently doing its work without any bother is also said to be interpreted to be in the leagues of daemon. –  Nikhil Mulley Dec 12 '11 at 7:40
add comment

migrated from serverfault.com Dec 12 '11 at 6:42

This question came from our site for professional system and network administrators.

2 Answers

up vote 6 down vote accepted

Neither. If you want to have it behave properly like a real daemon you should place it using the init system - /etc/init.d ( and make appropriate runlevel links in the appropriate /etc/rc.X folders )

Run a search or have a look at something like this: http://serverfault.com/questions/204695/comprehensive-guide-to-init-d-scripts

share|improve this answer
dear thinice,according to the link it say look for the skeletion file under the /etc/init.d I do not find under my centos? So what should I do next? –  newbie14 Dec 12 '11 at 8:49
just start it from /etc/rc.local like this: /path/to/my/binary & e.g. /usr/local/bin/newbie14program & running it from cron will also work: @reboot /usr/local/bin/newbie14program –  Folkert van Heusden Dec 12 '11 at 9:12
but according to thinice it wont behave well with cron? Ok I want to learn further from you regarding the /etc/rc.local? What must I do must I edit this file? What must I add. When I compile my C I get a an executable file as output? So what should I do next? –  newbie14 Dec 12 '11 at 12:46
... For starters, does your C program run as a daemon at all? IE, does it fork into the background so it can keep running even after you close the shell? –  Shadur Dec 12 '11 at 13:30
@Shadur 's question is important- if it is a daemon as you say, you should look in /etc/init.d - ls the directory, there should always be some sort of README-like file in there for setting up an init script. If it's not a daemon, then /etc/rc.local / crontab @reboot should work fine, you'll need to set your path in these files in most cases. –  thinice Dec 12 '11 at 14:58
show 4 more comments

Assuming that you're writing a network daemon, the easiest way would be to write your C program to interface to xinetd/inetd and leave the daemon-ing to the xinetd/inetd tool.

share|improve this answer
@sybreaon what this inetd? how better is this xinetd compare to daemontool because I am kind of confuse here too many methods? –  newbie14 Dec 20 '11 at 16:36
daemontools is designed to complement something like SysV init to start up services. inetd is a daemon itself and can be configured to execute external applications when something connects to it from the network. inetd can be found on all distros while daemontools less so. –  sybreon Dec 21 '11 at 1:38
@sybereon actually i am newbie into both this tools. Yes I have read about inetd is more link towards network stuff. So any good tutorial for me to start my daemon properly via it? Cause I google and found many confusing things. –  newbie14 Dec 21 '11 at 3:06
This is not a good place for a detailed guide. It might be better for you to ask specific questions that confuse you as individual questions. –  sybreon Dec 21 '11 at 14:37
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.