1
我試圖創建一個處理多個子線程的守護進程。但是子線程似乎並沒有將信號發送回父節點來調用該函數。我試圖把它從課堂上拿出來,並把它作爲一個標準功能,但這似乎也沒有幫助。SIGCHILD在子進程死時沒有捕獲信號
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();
顯然它工作,如果我添加declare(ticks = 1);令人困惑的是,這是從5.3棄用,但我無法找到什麼應該取代它的任何信息。 – DAB 2014-11-21 22:27:58
你應該做出答案。 – pilcrow 2014-11-22 04:00:38