diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 3f82fb56a88..87b17ae441b 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -233,7 +233,8 @@ If a `callback` function is provided, it is called with the arguments `error` will be an instance of [`Error`][]. The `error.code` property will be the exit code of the process. By convention, any exit code other than `0` indicates an error. `error.signal` will be the signal that terminated the -process. +process. `error.timedOut` will be `true` if the process was killed because +the `timeout` option expired. The `stdout` and `stderr` arguments passed to the callback will contain the stdout and stderr output of the child process. By default, Node.js will decode @@ -2314,6 +2315,32 @@ subprocess.stdout.on('data', (data) => { The `subprocess.stdout` property can be `null` or `undefined` if the child process could not be successfully spawned. +### `subprocess.timedOut` + + + +* Type: {boolean} Set to `true` when the child process is killed because the + `timeout` option expired. + +The `subprocess.timedOut` property indicates whether the `timeout` option of +[`child_process.spawn()`][], [`child_process.exec()`][], +[`child_process.execFile()`][] or [`child_process.fork()`][] expired and the +child process was sent the `killSignal` as a result. Like +[`subprocess.killed`][], it does not indicate that the child process has +terminated yet. + +```js +const { spawn } = require('node:child_process'); + +const subprocess = spawn('sleep', ['10'], { timeout: 100 }); + +subprocess.on('exit', (code, signal) => { + console.log(subprocess.timedOut); // true +}); +``` + ### `subprocess.unref()`