I am trying to create a c++ daemon that runs on a Red Hat 6.3 platform and am having trouble understanding the differences between the libc daemon()
call, the daemon
shell command, startproc
, start-stop-daemon
and about half a dozen other methods that google suggests for creating daemons.
I have seen suggestions that two forks
are needed, but calling daemon
only does one. Why is the second fork needed?
If I write the init.d script to call bash daemon
, does the c code still need to call daemon
?
I implemented my application to call the c daemon()
function since it seems the simplest solution, but I am running into the problem of my environment variables seem to get discarded. How do I prevent this?
I also need to run the daemon as a particular user, not as root.
What is the simplest way to create a C++ daemon that keeps its environment variables, runs as a specific user, and is started on system boot?