Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 505faf6

Browse filesBrowse files
eljefedelrodeodeljefeMyles Borins
authored andcommitted
doc: refine child_process detach behaviour
this adds an example of a long running node process that actually executes node code. Also it mentions the not to harmonic detach behaviours of the different platforms, whereas detaching on unix requires ignoring the child_process' stdio explicitely. PR-URL: #5330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 56dda6f commit 505faf6
Copy full SHA for 505faf6

File tree

Expand file treeCollapse file tree

1 file changed

+21
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-8
lines changed
Open diff view settings
Collapse file

‎doc/api/child_process.markdown‎

Copy file name to clipboardExpand all lines: doc/api/child_process.markdown
+21-8Lines changed: 21 additions & 8 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,27 @@ Doing so will cause the parent's event loop to not include the child in its
386386
reference count, allowing the parent to exit independently of the child, unless
387387
there is an established IPC channel between the child and parent.
388388

389-
Example of detaching a long-running process and redirecting its output to a
390-
file:
389+
When using the `detached` option to start a long-running process, the process
390+
will not stay running in the background after the parent exits unless it is
391+
provided with a `stdio` configuration that is not connected to the parent.
392+
If the parent's `stdio` is inherited, the child will remain attached to the
393+
controlling terminal.
394+
395+
Example of a long-running process, by detaching and also ignoring its parent
396+
`stdio` file descriptors, in order to ignore the parent's termination:
397+
398+
```js
399+
const spawn = require('child_process').spawn;
400+
401+
const child = spawn(process.argv[0], ['child_program.js'], {
402+
detached: true,
403+
stdio: ['ignore']
404+
});
405+
406+
child.unref();
407+
```
408+
409+
Alternatively one can redirect the child process' output into files:
391410

392411
```js
393412
const fs = require('fs');
@@ -403,12 +422,6 @@ const child = spawn('prg', [], {
403422
child.unref();
404423
```
405424

406-
When using the `detached` option to start a long-running process, the process
407-
will not stay running in the background after the parent exits unless it is
408-
provided with a `stdio` configuration that is not connected to the parent.
409-
If the parent's `stdio` is inherited, the child will remain attached to the
410-
controlling terminal.
411-
412425
#### options.stdio
413426

414427
The `options.stdio` option is used to configure the pipes that are established

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.