[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: How to start deamons?


> I have a *.c file ( runs in infinite loop ex while(1);)
> which I made as daemon using fork , setsid etc
> as maintioned in Richard Stevens Book. I want now this to start
> automatically when the system boots.

	First and foremost - avoid the loop to be plain while(1);. At
least write it as while(1) { sleep (1); }.
	Ok, now that apart, put your a.out in /etc/rc.d/init.d. Then
depending on your runlevel (normally, if you boot into text mode, then it
would be 3. If you get graphical login, then its 5), put a symlink from
/etc/rc.d/rc${runlevel}.d/ to a.out in init.d.
	One example is like this
[/etc/rc.d/rc3.d]$ ln -s ../init.d/a.out ./S35MyDaemon

	I am assuming here that your runlevel is 3, hence the current
directory while issueing the ln command is /etc/rc.d/rc3.d. For runlevel
other than that make relevant changes.
	If you look into /etc/rc.d/rc3.d, there would several symlinks
beginning with S and K. The number following is the sequence in which the
daemons are started and killed when that runlevel is entered or exited.
	In some daemons the sequence is important (e.g. nfsd should be
started only after portmap etc.), which is indicated by the number
following the S/K. In your case you can select any number, as there is
no dependancy.

Kedar N. Patankar.
Senior Software Engineer.
ishoni Networks
...Broadband for everyone
email - kedar@xxxxxxxxxx
Phone: +91-80-2292125 (Work)
Fax: +91-80-2995545 (Work)
Don't worry over what other people are thinking about you.
They're too busy worrying over what you are thinking about them.