Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1.22 pcntl_waitpid does not work #11916

Closed
bbonev opened this issue Aug 8, 2023 · 1 comment
Closed

PHP 8.1.22 pcntl_waitpid does not work #11916

bbonev opened this issue Aug 8, 2023 · 1 comment

Comments

@bbonev
Copy link

bbonev commented Aug 8, 2023

Description

The following code:

<?php
declare(ticks=1);

function dummy() {
	echo "got sigchild\n";
}

pcntl_signal(SIGCHLD,"dummy");

for ($i=0;$i<20;$i++)
	if (pcntl_fork()==0)
		pcntl_exec('/bin/sleep',["0.{$i}"]);

$done=0;
do {
	$st=-1;
	while (($pid=pcntl_waitpid(-1,$st,WNOHANG))>0)
		echo "got pid {$pid}\n";
	if ($pid==0)
		usleep(550);
} while (20>$done);

This loops forever on 8.1.22 but work as expected on 8.1.21 and earlier. In both cases I am getting the SIGCHLD signal but with 8.1.22 pcntl_waitpid always returns zero.

I have tried to get the pcntl.c from 8.1.21 and recompile 8.1.22 with it, then it works. I suspect that the problem is in f39b513 that calls waitpid inside the signal handler without buffering the results for pcntl_waitpid to fetch later (it calls wait4/waitpid), but I did not dig further.

It is also strange that pcntl_waitpid uses wait4/waitpid but pcntl_signal_handler doesn't do the same.

PHP Version

PHP 8.1.22

Operating System

No response

@nielsdos
Copy link
Member

nielsdos commented Aug 9, 2023

That commit is indeed the issue. This has been fixed in the current PHP-8.1 (and 8.2) development branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants