Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Process.php

function Process::doSignal

Sends a POSIX signal to the process.

Parameters

int $signal A valid POSIX signal (see https://php.net/pcntl.constants):

bool $throwException Whether to throw exception in case signal failed:

Throws

LogicException In case the process is not running

RuntimeException In case --enable-sigchild is activated and the process can't be killed

RuntimeException In case of failure

2 calls to Process::doSignal()
Process::signal in vendor/symfony/process/Process.php
Sends a POSIX signal to the process.
Process::stop in vendor/symfony/process/Process.php
Stops the process.

File

vendor/symfony/process/Process.php, line 1492

Class

Process
Process is a thin wrapper around proc_* functions to easily start independent PHP processes.

Namespace

Symfony\Component\Process

Code

private function doSignal(int $signal, bool $throwException) : bool {
    // Signal seems to be send when sigchild is enable, this allow blocking the signal correctly in this case
    if ($this->isSigchildEnabled() && \in_array($signal, $this->ignoredSignals)) {
        return false;
    }
    if (null === ($pid = $this->getPid())) {
        if ($throwException) {
            throw new LogicException('Cannot send signal on a non running process.');
        }
        return false;
    }
    if ('\\' === \DIRECTORY_SEPARATOR) {
        exec(\sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode);
        if ($exitCode && $this->isRunning()) {
            if ($throwException) {
                throw new RuntimeException(\sprintf('Unable to kill the process (%s).', implode(' ', $output)));
            }
            return false;
        }
    }
    else {
        if (!$this->isSigchildEnabled()) {
            $ok = @proc_terminate($this->process, $signal);
        }
        elseif (\function_exists('posix_kill')) {
            $ok = @posix_kill($pid, $signal);
        }
        elseif ($ok = proc_open(\sprintf('kill -%d %d', $signal, $pid), [
            2 => [
                'pipe',
                'w',
            ],
        ], $pipes)) {
            $ok = false === fgets($pipes[2]);
        }
        if (!$ok) {
            if ($throwException) {
                throw new RuntimeException(\sprintf('Error while sending signal "%s".', $signal));
            }
            return false;
        }
    }
    $this->latestSignal = $signal;
    $this->fallbackStatus['signaled'] = true;
    $this->fallbackStatus['exitcode'] = -1;
    $this->fallbackStatus['termsig'] = $this->latestSignal;
    return true;
}
RSS feed
Powered by Drupal