[php-src] Issue #11916: PHP 8.1.22 pcntl_waitpid does not work

From: Date: Tue, 08 Aug 2023 22:55:44 +0000
Subject: [php-src] Issue #11916: PHP 8.1.22 pcntl_waitpid does not work
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245133@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11916 Author: bbonev ### Description The following code: ```php <?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 f39b5139161f3e31fcb7e6bd2e3b7c89dc4ae53c that calls waitpid inside the signal handler without buffering the results for pcntl_waitpid to fetch later (it calls wait4/waitpid), but 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_

« previous php.bugs (#245133) next »