@@ -89,35 +89,36 @@ callbackFunction((err, ret) => {
8989});
9090```
9191
92- ## ` util.convertProcessSignalToExitCode(signalCode ) `
92+ ## ` util.convertProcessSignalToExitCode(signal ) `
9393
9494<!-- YAML
9595added:
9696 - v25.4.0
9797 - v24.14.0
9898-->
9999
100- * ` signalCode ` {string} A signal name (e.g., ` 'SIGTERM' ` , ` 'SIGKILL' ` ).
101- * Returns: {number|null } The exit code, or ` null ` if the signal is invalid.
100+ * ` signal ` {string} A signal name (e.g. ` 'SIGTERM' ` )
101+ * Returns: {number} The exit code corresponding to ` signal `
102102
103103The ` util.convertProcessSignalToExitCode() ` method converts a signal name to its
104104corresponding POSIX exit code. Following the POSIX standard, the exit code
105105for a process terminated by a signal is calculated as ` 128 + signal number ` .
106106
107+ If ` signal ` is not a valid signal name, then an error will be thrown. See
108+ [ ` signal(7) ` ] [ ] for a list of valid signals.
109+
107110``` mjs
108111import { convertProcessSignalToExitCode } from ' node:util' ;
109112
110113console .log (convertProcessSignalToExitCode (' SIGTERM' )); // 143 (128 + 15)
111114console .log (convertProcessSignalToExitCode (' SIGKILL' )); // 137 (128 + 9)
112- console .log (convertProcessSignalToExitCode (' INVALID' )); // null
113115```
114116
115117``` cjs
116118const { convertProcessSignalToExitCode } = require (' node:util' );
117119
118120console .log (convertProcessSignalToExitCode (' SIGTERM' )); // 143 (128 + 15)
119121console .log (convertProcessSignalToExitCode (' SIGKILL' )); // 137 (128 + 9)
120- console .log (convertProcessSignalToExitCode (' INVALID' )); // null
121122```
122123
123124This is particularly useful when working with processes to determine
@@ -3869,6 +3870,7 @@ npx codemod@latest @nodejs/util-is
38693870[` mime .toString ()` ]: #mimetostring
38703871[` mimeParams .entries ()` ]: #mimeparamsentries
38713872[` napi_create_external ()` ]: n-api.md#napi_create_external
3873+ [` signal (7 )` ]: https://man7.org/linux/man-pages/man7/signal.7.html
38723874[` target` and ` handler` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#terminology
38733875[` tty .hasColors ()` ]: tty.md#writestreamhascolorscount-env
38743876[` util .diff ()` ]: #utildiffactual-expected
0 commit comments