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)
This is particularly useful when working with processes to determine the exit code based on the signal that terminated the process.