mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
doc: correct util.convertProcessSignalToExitCode validation behavior
PR-URL: https://github.com/nodejs/node/pull/62134 Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
5439d0e0cf
commit
83719ffb64
1 file changed
+7
-5
+7
-5
@@ -89,25 +89,27 @@ callbackFunction((err, ret) => {
|
||||
});
|
||||
```
|
||||
|
||||
## `util.convertProcessSignalToExitCode(signalCode)`
|
||||
## `util.convertProcessSignalToExitCode(signal)`
|
||||
|
||||
<!-- YAML
|
||||
added: v25.4.0
|
||||
-->
|
||||
|
||||
* `signalCode` {string} A signal name (e.g., `'SIGTERM'`, `'SIGKILL'`).
|
||||
* Returns: {number|null} The exit code, or `null` if the signal is invalid.
|
||||
* `signal` {string} A signal name (e.g. `'SIGTERM'`)
|
||||
* Returns: {number} The exit code corresponding to `signal`
|
||||
|
||||
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.
|
||||
|
||||
```mjs
|
||||
import { convertProcessSignalToExitCode } from 'node:util';
|
||||
|
||||
console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15)
|
||||
console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9)
|
||||
console.log(convertProcessSignalToExitCode('INVALID')); // null
|
||||
```
|
||||
|
||||
```cjs
|
||||
@@ -115,7 +117,6 @@ const { convertProcessSignalToExitCode } = require('node:util');
|
||||
|
||||
console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15)
|
||||
console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9)
|
||||
console.log(convertProcessSignalToExitCode('INVALID')); // null
|
||||
```
|
||||
|
||||
This is particularly useful when working with processes to determine
|
||||
@@ -3864,6 +3865,7 @@ npx codemod@latest @nodejs/util-is
|
||||
[`mime.toString()`]: #mimetostring
|
||||
[`mimeParams.entries()`]: #mimeparamsentries
|
||||
[`napi_create_external()`]: n-api.md#napi_create_external
|
||||
[`signal(7)`]: https://man7.org/linux/man-pages/man7/signal.7.html
|
||||
[`target` and `handler`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#terminology
|
||||
[`tty.hasColors()`]: tty.md#writestreamhascolorscount-env
|
||||
[`util.diff()`]: #utildiffactual-expected
|
||||
|
||||
Reference in new issue
Block a user