Skip to content

Commit ccf99c9

Browse files
committed
fixup! doc: document convertProcessSignalToExitCode usage
1 parent 8337df1 commit ccf99c9

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

doc/api/child_process.md

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,42 +1547,6 @@ exited, `code` is the final exit code of the process, otherwise `null`. If the
15471547
process terminated due to receipt of a signal, `signal` is the string name of
15481548
the signal, otherwise `null`. One of the two will always be non-`null`.
15491549
1550-
When `code` is `null` due to signal termination, you can use
1551-
[`util.convertProcessSignalToExitCode()`][] to convert the signal to a POSIX
1552-
exit code.
1553-
1554-
```cjs
1555-
const { spawn } = require('node:child_process');
1556-
const { convertProcessSignalToExitCode } = require('node:util');
1557-
1558-
const ls = spawn('ls', ['-lh', '/usr']);
1559-
1560-
ls.kill();
1561-
1562-
ls.on('exit', (code, signal) => {
1563-
const exitCode = convertProcessSignalToExitCode(signal);
1564-
console.log(`signal ${signal}, POSIX exit code: ${exitCode}`);
1565-
});
1566-
1567-
// signal SIGTERM, POSIX exit code: 143
1568-
```
1569-
1570-
```mjs
1571-
import { spawn } from 'node:child_process';
1572-
import { once } from 'node:events';
1573-
import { convertProcessSignalToExitCode } from 'node:util';
1574-
1575-
const ls = spawn('ls', ['-lh', '/usr']);
1576-
1577-
ls.kill();
1578-
1579-
const [code, signal] = await once(ls, 'exit');
1580-
const exitCode = convertProcessSignalToExitCode(signal);
1581-
console.log(`signal ${signal}, POSIX exit code: ${exitCode}`);
1582-
1583-
// signal SIGTERM, POSIX exit code: 143
1584-
```
1585-
15861550
When the `'exit'` event is triggered, child process stdio streams might still be
15871551
open.
15881552
@@ -1593,6 +1557,10 @@ re-raise the handled signal.
15931557
15941558
See waitpid(2).
15951559
1560+
When `code` is `null` due to signal termination, you can use
1561+
[`util.convertProcessSignalToExitCode()`][] to convert the signal to a POSIX
1562+
exit code.
1563+
15961564
### Event: `'message'`
15971565
15981566
<!-- YAML
@@ -1708,7 +1676,8 @@ The `subprocess.exitCode` property indicates the exit code of the child process.
17081676
If the child process is still running, the field will be `null`.
17091677
17101678
When the child process is terminated by a signal, `subprocess.exitCode` will be
1711-
`null`. To get the corresponding POSIX exit code, use
1679+
`null` and [`subprocess.signalCode`][] will be set. To get the corresponding
1680+
POSIX exit code, use
17121681
[`util.convertProcessSignalToExitCode(subprocess.signalCode)`][`util.convertProcessSignalToExitCode()`].
17131682
17141683
### `subprocess.kill([signal])`
@@ -2147,6 +2116,10 @@ connection to the child.
21472116
The `subprocess.signalCode` property indicates the signal received by
21482117
the child process if any, else `null`.
21492118
2119+
When the child process is terminated by a signal, [`subprocess.exitCode`][] will be `null`.
2120+
To get the corresponding POSIX exit code, use
2121+
[`util.convertProcessSignalToExitCode(subprocess.signalCode)`][`util.convertProcessSignalToExitCode()`].
2122+
21502123
### `subprocess.spawnargs`
21512124
21522125
* Type: {Array}
@@ -2427,8 +2400,10 @@ or [`child_process.fork()`][].
24272400
[`stdio`]: #optionsstdio
24282401
[`subprocess.connected`]: #subprocessconnected
24292402
[`subprocess.disconnect()`]: #subprocessdisconnect
2403+
[`subprocess.exitCode`]: #subprocessexitcode
24302404
[`subprocess.kill()`]: #subprocesskillsignal
24312405
[`subprocess.send()`]: #subprocesssendmessage-sendhandle-options-callback
2406+
[`subprocess.signalCode`]: #subprocesssignalcode
24322407
[`subprocess.stderr`]: #subprocessstderr
24332408
[`subprocess.stdin`]: #subprocessstdin
24342409
[`subprocess.stdio`]: #subprocessstdio

0 commit comments

Comments
 (0)