[php-src] Issue #12161: pcntl_wait suspend forever to wait child process finishing

From: Date: Sat, 09 Sep 2023 01:01:25 +0000
Subject: [php-src] Issue #12161: pcntl_wait suspend forever to wait child process finishing
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245367@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12161 Author: walkonthemarz ### Description The following code: ```php <?php echo 'Before forked, PID=', getmypid(), PHP_EOL; $pid = pcntl_fork(); if ($pid === -1) { echo 'failed to fork.', PHP_EOL; } elseif ($pid === 0) { echo 'This is child process. PID=', getmypid() . PHP_EOL; sleep(5); //$sleep = 5; //echo 'Sleeping for ', $sleep, ' seconds', PHP_EOL; // if (extension_loaded('posix')) { // posix_kill(getmypid(), SIGKILL); // } exit; } else { echo 'This is parent process, forked child process ID: ', $pid, PHP_EOL; echo 'Waiting for child process to finish...', PHP_EOL; //while ( $pid !== pcntl_waitpid($pid, $status, WNOHANG|WUNTRACED)) { // //echo 'Waiting.....', PHP_EOL; //} // $pid = pcntl_waitpid($pid, $status); pcntl_wait($status); //echo 'Child process ID ', $pid, ' exited, status=', $status, PHP_EOL; echo "parent shut down." . PHP_EOL; } ``` Resulted in this output: ``` Before forked, PID=49309 This is parent process, forked child process ID: 49310 Waiting for child process to finish... This is child process. PID=49310 ``` But the process never finishs and it hangs in air. I checked the process status in terminal as the below. ![CleanShot 2023-09-09 at 08 40 38@2x](https://github.com/php/php-src/assets/9317172/de026ac4-0b86-4e27-b872-bd1766cdca9f) Am i making something wrong with this? Or there are additional info that not documented. ### PHP Version PHP 8.2.8 (cli) (built: Jul 6 2023 11:16:57) (NTS) ### Operating System MacOS Ventura Version 13.5.1 (22G90)

« previous php.bugs (#245367) next »