M
util.convertProcessSignalToExitCode
History
Added in: v25.4.0, v24.14.0
v25.4.0, v24.14.0
Introduced in: v0.10.0
v0.10.0
util.convertProcessSignalToExitCode(signal): number
Attributes
The util.convertProcessSignalToExitCode() method converts a signal name to its
corresponding POSIX exit code. Following the POSIX standard, the exit code
for a process terminated by a signal is calculated as 128 + signal number.
If signal is not a valid signal name, then an error will be thrown. See
signal(7) for a list of valid signals.
import { convertProcessSignalToExitCode } from 'node:util'; console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15) console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9)
const { convertProcessSignalToExitCode } = require('node:util'); console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15) console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9)
This is particularly useful when working with processes to determine the exit code based on the signal that terminated the process.