I would delegate daemon management to an external tool, like daemontools. As a nice side effect, this completely eliminates the need for PID files. The apache handler would simply invoke the svc command with proper arguments, e.g. system('/command/svc','-u','/service/mydaemon'), or more likely, invoke it via sudo so apache does not run as root: system('/usr/bin/sudo','/command/svc','-u','/service/mydaemon'). The daemon does not need any daemonizing code, you write it as a simple foreground command line tool, the daemontools take care of managing the process, including backgrounding, error logging, signals, restarts, changing user and group id, environment, and so on. See http://thedjbway.org/daemontools.html for a human readable introduction.
(And please don't chmod 777 any file or directory without a VERY good reason, especially not on systems connected to any kind of network.)
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] [select] |