Creating a Daemon

I need to make a process into a daemon either through the command line or programmatically.  (command line, preferred)

dpengAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
harrysConnect With a Mentor Commented:
from the comandline you could start it with
daemon&
which pushes it to the background.
in a program you would call fork() which starts a childprocess, then  inside the child  close the  stdin/stdout/stderr filehandles (see the manualpage of fork for details how
to detect who the child is..) and the child is you new daemon. inside the parent just
terminate the process.

0
 
overcodeCommented:
Linux Journal ran an article on daemons a while back, complete with code samples. It might be available on their web site.

-Reeves
0
 
bentenCommented:
What do you mean by a daemon?  Most programs that are considered daemons first fork a new process, orphan the child (by having the parent exit), close all the file descriptors and reset the session ids.
0
 
dpengAuthor Commented:
Alright I'll try it out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.