diff --git a/src/Fork.php b/src/Fork.php index 5aef9f5..5647412 100644 --- a/src/Fork.php +++ b/src/Fork.php @@ -157,11 +157,15 @@ protected function listenForSignals(): void protected function exit(): void { - if (extension_loaded('posix')) { - posix_kill(getmypid(), SIGKILL); + if (! extension_loaded('posix')) { + exit; } - exit; + foreach ($this->runningTasks as $task) { + posix_kill($task->pid(), SIGKILL); + } + + posix_kill(getmypid(), SIGKILL); } protected function currentlyInChildTask(int $pid): bool diff --git a/tests/ForkTest.php b/tests/ForkTest.php index 94eb919..9222b7d 100644 --- a/tests/ForkTest.php +++ b/tests/ForkTest.php @@ -11,7 +11,7 @@ ) )->toEqual([2, 4]); -it('will execute the given closure with concurrency cap ', function () { +it('will execute the given closure with concurrency cap', function () { $results = Fork::new() ->concurrent(2) ->run(