I am trying to use posix_kill(0, $signo); to signal children forked by the parent. All children seem to be in the processgroup of the parent, but sending either 0 or -10 does not seem to signal the children at all.
What am I doing wrong? I even tried setting the process group (didn't affect anything). It doesn't seem like sending the kill to 0 reaches the children.
Has anybody used pcntl and posix_kill with success and if so, could you provide me a code sniplet?
Here is my main:
function main()
{
global $logfile;
$logfile = "/tmp/runner.log.".date("Ymd:Hi"); //posix_setsid();
pcntl_signal(SIGINT, array("runner","sig_handler_parent"));
pcntl_signal(SIGTERM, array("runner","sig_handler_parent"));
pcntl_signal(SIGHUP, array("runner","sig_handler_parent"));
pcntl_signal(SIGUSR1, array("runner","sig_handler_parent")); do {
if ($this->numChildren <= MAXCHILDREN && $this->count > 0) {
$pid = pcntl_fork();
if ($pid < 0) {
die("could not fork");
} elseif ($pid == 0) {
$ret = $this->child($args);
exit ($ret);
} else {
$this->log("Child Started: [PID:$pid] -> [JOB:test]");
$this->numChildren++;
// posix_setpgid($pid,posix_getpgid($this->pid));
$this->count--;
}
}
// sleep(5);
$out = pcntl_waitpid ( -1, &$status, WNOHANG );
if ($out > 0) {
$this->numChildren--;
}} while ($this->count > 0 || $this->numChildren > 1);
echo "Done \n"; }
function sig_handler_parent($signo)
{
switch($signo) {
case SIGINT:
case SIGUSR1;
case SIGTERM:
posix_kill(0, $signo);
exit;
break;
case SIGHUP:
// handle restart tasks
echo "SIGHUP\n";
break;
default:
echo "ANOTHER EVENT\n";
// handle all other signals
}
}
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

