From d51bd9a48714c2efab9581b3bf2668e352806f67 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 26 Feb 2019 09:44:39 -0600 Subject: [PATCH] Send signals to child process instead of wrapper --- lib/Internal/Posix/Runner.php | 11 +++++++---- test/ProcessTest.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Internal/Posix/Runner.php b/lib/Internal/Posix/Runner.php index 213341f..012e8d3 100644 --- a/lib/Internal/Posix/Runner.php +++ b/lib/Internal/Posix/Runner.php @@ -204,10 +204,13 @@ final class Runner implements ProcessRunner /** @inheritdoc */ public function signal(ProcessHandle $handle, int $signo) { - /** @var Handle $handle */ - if (!\proc_terminate($handle->proc, $signo)) { - throw new ProcessException("Sending signal to process failed"); - } + $handle->pidDeferred->promise()->onResolve(function ($error, $pid) use ($signo) { + if ($error) { + return; + } + + @\posix_kill($pid, $signo); + }); } /** @inheritdoc */ diff --git a/test/ProcessTest.php b/test/ProcessTest.php index 9c40e77..ee1c8d5 100644 --- a/test/ProcessTest.php +++ b/test/ProcessTest.php @@ -375,6 +375,17 @@ class ProcessTest extends TestCase }); } + public function testSignal() + { + Loop::run(function () { + $process = new Process(["php", __DIR__ . "/bin/signal-process.php"]); + yield $process->start(); + yield new Delayed(100); // Give process time to set up single handler. + $process->signal(\SIGTERM); + $this->assertSame(42, yield $process->join()); + }); + } + public function testDebugInfo() { Loop::run(function () {