Re: Start/stop daemon using php

From: Date: Wed, 27 Feb 2008 13:30:48 +0000
Subject: Re: Start/stop daemon using php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-270280@lists.php.net to get a copy of this message
David Sveningsson schreef:
Hi, I've written an application in c which I would like to start/stop as a daemon in gnu/linux. The application has the argument "--daemon" which forks the process and exits the parent. Then it setups a SIGQUIT signal handler to properly cleanup and terminate. It also maintains a lockfile (with the pid) so only one instance is allowed. So, to start this application I created a php site that calls exec("/path/to/binary --daemon > /dev/null 2> /dev/null"). Everything is working so far, but I cannot get the application to receive the SIGQUIT when I start using php and exec. Not even manually using kill in the shell. It works correctly if I start manually thought. So, is this possible to do? Doesn't exec allow applications with signal handlers? Is there some other way to terminate the application?
there is nothing special about exec that makes working with the kill command different to anything else, though you might take a look at the posix_kill() command instead. e.g. posix_kill(cat /path/to/pidfile, SIGQUIT); you say you can't even send SIGQUIT to the daemon using kill on the command line, this suggests the problem lies in the fact that the daemon's signal handler is not actually working (when the process is daemonized).


« previous php.general (#270280) next »