複数の子スレッドを処理するデーモン プロセスを作成しようとしています。しかし、子スレッドは関数を呼び出すためにシグナルを親に送り返していないようです。私はそれをクラスから取り出して標準関数にしようとしましたが、それも役に立たないようです。
class Daemon {
public function __construct() {
$set = pcntl_signal(SIGCHLD, array($this, 'childSignalHandler'));
$pid = pcntl_fork();
if ($pid == -1) {
echo 'could not fork';
} elseif ($pid) {
// parent
sleep(20);
// this would keep running and spawn other children from time to time
} else {
// child
sleep(5);
// should call childSignalHandler() in parent
}
}
public function childSignalHandler($pid) {
echo 'child is dead';
}
}
new Daemon();