@@ -305,8 +305,8 @@ protected static function waitProcessExits(int $pid, ?LoopInterface $loop = null
305305 }
306306 $ defer = new Deferred ();
307307 $ timer = $ loop ->addPeriodicTimer (0.001 , function () use ($ pid , $ defer ) {
308- $ r = pcntl_waitpid ($ pid, $ status , \ WNOHANG );
309- if (! $ r ) {
308+ $ r = zombie_reap ($ pid );
309+ if ($ r >= 0 ) {
310310 $ defer ->resolve ($ r );
311311 }
312312 });
@@ -333,10 +333,8 @@ protected static function killProcess(int $pid, int $signal=15, ?LoopInterface $
333333 foreach ($ pids as $ pid ) {
334334 $ pid = intval ($ pid );
335335 if ($ pid ) {
336- posix_kill ($ pid , $ signal );
337- if ($ loop ) {
338- $ promises [] = static ::waitProcessExits ($ pid , $ loop );
339- }
336+ $ promises [$ pid ] = static ::waitProcessExits ($ pid , $ loop );
337+ zombie_kill ($ pid );
340338 }
341339 }
342340 if ($ loop ) {
@@ -432,6 +430,10 @@ public static function executeWithLoop(LoopInterface $loop, string $cmd, float $
432430 foreach ($ proc ->pipes as $ pipe ) {
433431 $ pipe ->close ();
434432 }
433+ $ pid = $ proc ->getPid ();
434+ if ($ pid ) {
435+ static ::killProcess ($ pid , 15 , $ loop );
436+ }
435437 if ($ err ) {
436438 return $ defer ->reject ($ err );
437439 }
@@ -442,10 +444,6 @@ public static function executeWithLoop(LoopInterface $loop, string $cmd, float $
442444 return $ defer ->reject (new Exception ('Process exited with code: ' . $ exitCode . "\n$ buffer " , $ exitCode , $ trace ));
443445 }
444446 $ defer ->resolve ($ buffer );
445- $ pid = $ proc ->getPid ();
446- if ($ pid ) {
447- static ::killProcess ($ pid , 15 , $ loop );
448- }
449447 });
450448 });
451449 return $ defer ->promise ();
@@ -599,7 +597,7 @@ public static function asyncWithLoop(LoopInterface $loop, $fn, array $args = [])
599597 $ pid = false ;
600598 $ id = bin2hex (random_bytes (16 ));
601599 $ trace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 3 );
602- $ defer = new Deferred (function () use (&$ pid , $ loop ) {
600+ $ defer = new Deferred (function () use ($ id , &$ pid , $ loop ) {
603601 static ::removeFork ($ id );
604602 if ($ pid ) {
605603 static ::killProcess ($ pid , 9 , $ loop );
0 commit comments