私は親/就労協定を結んでいます。親は常に彼らはまだ、次のループで生きていることを確認し、配列内の労働者のPIDを保持します:
// $workers is an array of PIDs
foreach ($workers as $workerID => $pid) {
// Check if this worker still exists as a process
pcntl_waitpid($pid, $status, WNOHANG|WUNTRACED);
// If the worker exited normally, stop tracking it
if (pcntl_wifexited($status)) {
$logger->info("Worker $workerID exited normally");
array_splice($workers, $workerID, 1);
}
// If it has a session ID, then it's still living
if (posix_getsid($pid))⋅
$living[] = $pid;
}
// $dead is the difference between workers we've started
// and those that are still running
$dead = array_diff($workers, $living);
問題はpcntl_waitpid()
は常に0に$status
を設定しているので、非常に最初の時間は、このループが実行されるということです親は、まだ実行中であっても、すべての子どもが正常に終了したと考えます。 pcntl_waitpid()
を間違って使用していますか、それともそうでないことを期待していますか?