Skip to content

[Process] Difference between Mac and Linux #11543

@alexandresalome

Description

@alexandresalome

I have a weird case using the Process component and the ->stop() method:

With the following code:

$process = new Symfony\Component\Process\Process('echo ok; sleep 1; echo ok; sleep 2; echo ko; sleep 5');
$process->run(function ($type, $output) use ($process) {
    if (false !== strpos($output, 'ko')) {
        $process->stop();
    }
});
var_dump($process->getExitCode());

On Linux: The code executes correctly, I get int(143) (the return code).

On Mac: I get an exception (thrown by the component):

 PHP Fatal error:  Uncaught exception 'Symfony\Component\Process\Exception\RuntimeException' with message 'The process has been signaled with signal "15".' in /sf-std/vendor/symfony/process/Symfony/Component/Process/Process.php:359
Stack trace:
#0 /sf-std/vendor/symfony/process/Symfony/Component/Process/Process.php(204): Symfony\Component\Process\Process->wait()
#1 /sf-std/test.php(10): Symfony\Component\Process\Process->run(Object(Closure))
#2 {main}
  thrown in /sf-std/vendor/symfony/process/Symfony/Component/Process/Process.php on line 359

Fatal error: Uncaught exception 'Symfony\Component\Process\Exception\RuntimeException' with message 'The process has been signaled with signal "15".' in /sf-std/vendor/symfony/process/Symfony/Component/Process/Process.php:359
Stack trace:
#0 /sf-std/vendor/symfony/process/Symfony/Component/Process/Process.php(204): Symfony\Component\Process\Process->wait()
#1 /sf-std/test.php(10): Symfony\Component\Process\Process->run(Object(Closure))
#2 {main}
  thrown in /sf-std/vendor/symfony/process/Symfony/Component/Process/Process.php on line 359

And what is really weird: it doesn't happen when I stop the process outside of the `->run()`` method. The following code run the same on Linux/Mac (return code: 143).

$process = new Symfony\Component\Process\Process('sleep 10');
$process->start();
sleep(1);
$process->stop();
var_dump($process->getExitCode());

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions