{"record":{"id":"3f3c96d80d8e1f9e","repo":"symfony/process","slug":"error-while-sending-signal-s","errorCode":null,"errorMessage":"Error while sending signal \"%s\".","messagePattern":"Error while sending signal \"(.+?)\"\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Process.php","lineNumber":1554,"sourceCode":"            exec(\\sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode);\n            if ($exitCode && $this->isRunning()) {\n                if ($throwException) {\n                    throw new RuntimeException(\\sprintf('Unable to kill the process (%s).', implode(' ', $output)));\n                }\n\n                return false;\n            }\n        } else {\n            if (!$this->isSigchildEnabled()) {\n                $ok = @proc_terminate($this->process, $signal);\n            } elseif (\\function_exists('posix_kill')) {\n                $ok = @posix_kill($pid, $signal);\n            } elseif ($ok = proc_open(\\sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {\n                $ok = false === fgets($pipes[2]);\n            }\n            if (!$ok) {\n                if ($throwException) {\n                    throw new RuntimeException(\\sprintf('Error while sending signal \"%s\".', $signal));\n                }\n\n                return false;\n            }\n        }\n\n        $this->latestSignal = $signal;\n        $this->fallbackStatus['signaled'] = true;\n        $this->fallbackStatus['exitcode'] = -1;\n        $this->fallbackStatus['termsig'] = $this->latestSignal;\n\n        return true;\n    }\n\n    /**\n     * @param string|list<string> $commandline\n     */\n    private function buildShellCommandline(string|array $commandline): string","sourceCodeStart":1536,"sourceCodeEnd":1572,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Process.php#L1536-L1572","documentation":"On POSIX systems doSignal() sends the signal via posix_kill or a 'kill' proc_open. If both fail (sigchild disabled and posix_kill returns false, or the kill command reported an error), a RuntimeException 'Error while sending signal \"%s\".' is thrown when $throwException is true.","triggerScenarios":"Signaling a PID that just exited (ESRCH), running under an environment without the posix extension and without a working kill binary (sigchild environments), lacking permission for the target process.","commonSituations":"Docker minimal images without posix/procps, signaling as unprivileged user a process owned by another user, race where the child terminates before the signal arrives.","solutions":["Install/enable the ext-posix extension so posix_kill is used","Check isRunning() before signaling to avoid signaling dead PIDs","Catch RuntimeException and treat as best-effort termination"],"exampleFix":"// before\n$process->signal(SIGTERM); // RuntimeException in minimal containers\n// after\nif ($process->isRunning()) {\n    try {\n        $process->signal(SIGTERM);\n    } catch (RuntimeException $e) {\n        // fallback: wait for exit or force stop\n    }\n}","handlingStrategy":"try-catch","validationCode":"if (!function_exists('posix_kill')) { /* sigchild environment: be prepared for fallback */ }\nif (!$process->isRunning()) { return; }","typeGuard":null,"tryCatchPattern":"try { $process->signal($sig); } catch (RuntimeException $e) { /* best-effort: log and wait for exit */ }","preventionTips":["Install ext-posix in containers/production images","Avoid signaling processes that may have just exited","Treat signals as best-effort; always wait()/check exit afterwards"],"tags":["php","process","posix","signal"],"backgroundTag":"command-failed","analyzedSha":"99b85026db14a68f02c6f3eeb01a1170ca25c491","analyzedAt":"2026-09-14T11:23:33.683Z","contentChangedAt":"2026-09-14T11:23:33.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}