我正在尝试创建一个处理多个子线程的守护进程。但是子线程似乎没有将信号发送回父线程以调用该函数。我试图把它从课堂上拿出来,让它成为标准功能,但这似乎也无济于事。
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();