From fd500477acca903fd5470801d8a9edf20f2a5654 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 22 Oct 2024 19:09:33 +0200 Subject: [PATCH] docs: clarify utilityProcess child.pid value (#44339) --- docs/api/utility-process.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/api/utility-process.md b/docs/api/utility-process.md index bb78e576490..f503fa9387f 100644 --- a/docs/api/utility-process.md +++ b/docs/api/utility-process.md @@ -86,9 +86,21 @@ true if the kill is successful, and false otherwise. #### `child.pid` A `Integer | undefined` representing the process identifier (PID) of the child process. -If the child process fails to spawn due to errors, then the value is `undefined`. When +Until the child process has spawned successfully, the value is `undefined`. When the child process exits, then the value is `undefined` after the `exit` event is emitted. +```js +const child = utilityProcess.fork(path.join(__dirname, 'test.js')) + +child.on('spawn', () => { + console.log(child.pid) // Integer +}) + +child.on('exit', () => { + console.log(child.pid) // undefined +}) +``` + #### `child.stdout` A `NodeJS.ReadableStream | null` that represents the child process's stdout.