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 781290b

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 8317778 commit 781290b
Copy full SHA for 781290b

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
@@ -405,8 +405,27 @@ Doing so will cause the parent's event loop to not include the child in its
405405
reference count, allowing the parent to exit independently of the child, unless
406406
there is an established IPC channel between the child and parent.
407407

408-
Example of detaching a long-running process and redirecting its output to a
409-
file:
408+
When using the `detached` option to start a long-running process, the process
409+
will not stay running in the background after the parent exits unless it is
410+
provided with a `stdio` configuration that is not connected to the parent.
411+
If the parent's `stdio` is inherited, the child will remain attached to the
412+
controlling terminal.
413+
414+
Example of a long-running process, by detaching and also ignoring its parent
415+
`stdio` file descriptors, in order to ignore the parent's termination:
416+
417+
```js
418+
const spawn = require('child_process').spawn;
419+
420+
const child = spawn(process.argv[0], ['child_program.js'], {
421+
detached: true,
422+
stdio: ['ignore']
423+
});
424+
425+
child.unref();
426+
```
427+
428+
Alternatively one can redirect the child process' output into files:
410429

411430
```js
412431
const fs = require('fs');
@@ -422,12 +441,6 @@ const child = spawn('prg', [], {
422441
child.unref();
423442
```
424443

425-
When using the `detached` option to start a long-running process, the process
426-
will not stay running in the background after the parent exits unless it is
427-
provided with a `stdio` configuration that is not connected to the parent.
428-
If the parent's `stdio` is inherited, the child will remain attached to the
429-
controlling terminal.
430-
431444
#### options.stdio
432445

433446
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.