Skip to content

Commit b08b955

Browse files
committed
Fix test 013: loop pcntl_waitpid until zombie is ready
After pipe EOF there's a small window before the child becomes a zombie. A single WNOHANG waitpid can miss it, returning 0. Loop with 1ms delay until the zombie is actually reapable.
1 parent cc130df commit b08b955

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tests/exec/013-proc_close_child_already_reaped.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ $c = spawn(function() use ($php) {
3838

3939
// Simulate external reaping (like Go runtime doing waitpid(-1))
4040
// This steals the zombie before proc_close can get it.
41+
// Loop because there's a small window between pipe EOF and zombie state.
4142
$reap_status = 0;
42-
$reaped = pcntl_waitpid($pid, $reap_status, WNOHANG);
43+
do {
44+
$reaped = pcntl_waitpid($pid, $reap_status, WNOHANG);
45+
if ($reaped === 0) usleep(1000);
46+
} while ($reaped === 0);
4347
echo "Zombie reaped externally, exit=" . pcntl_wexitstatus($reap_status) . "\n";
4448

4549
fclose($pipes[0]);

0 commit comments

Comments
 (0)