summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRobert Jefe Lindstaedt <robert.lindstaedt@gmail.com>2016-02-19 21:17:24 +0100
committerJames M Snell <jasnell@gmail.com>2016-04-01 22:57:08 -0700
commit82c2996e2df042848f2c088f31d97b224509d439 (patch)
treedad091cb5558e5258b404d0f06966d34a46b72fc /doc
parentd7987d9c35391f3d5036ddec59a4c441dbd4c374 (diff)
downloadandroid-node-v8-82c2996e2df042848f2c088f31d97b224509d439.tar.gz
android-node-v8-82c2996e2df042848f2c088f31d97b224509d439.tar.bz2
android-node-v8-82c2996e2df042848f2c088f31d97b224509d439.zip
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: https://github.com/nodejs/node/pull/5330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/child_process.markdown29
1 files changed, 21 insertions, 8 deletions
diff --git a/doc/api/child_process.markdown b/doc/api/child_process.markdown
index 5f17b435e6..bb7dcf4560 100644
--- a/doc/api/child_process.markdown
+++ b/doc/api/child_process.markdown
@@ -391,8 +391,27 @@ Doing so will cause the parent's event loop to not include the child in its
reference count, allowing the parent to exit independently of the child, unless
there is an established IPC channel between the child and parent.
-Example of detaching a long-running process and redirecting its output to a
-file:
+When using the `detached` option to start a long-running process, the process
+will not stay running in the background after the parent exits unless it is
+provided with a `stdio` configuration that is not connected to the parent.
+If the parent's `stdio` is inherited, the child will remain attached to the
+controlling terminal.
+
+Example of a long-running process, by detaching and also ignoring its parent
+`stdio` file descriptors, in order to ignore the parent's termination:
+
+```js
+const spawn = require('child_process').spawn;
+
+const child = spawn(process.argv[0], ['child_program.js'], {
+ detached: true,
+ stdio: ['ignore']
+});
+
+child.unref();
+```
+
+Alternatively one can redirect the child process' output into files:
```js
const fs = require('fs');
@@ -408,12 +427,6 @@ const child = spawn('prg', [], {
child.unref();
```
-When using the `detached` option to start a long-running process, the process
-will not stay running in the background after the parent exits unless it is
-provided with a `stdio` configuration that is not connected to the parent.
-If the parent's `stdio` is inherited, the child will remain attached to the
-controlling terminal.
-
#### options.stdio
The `options.stdio` option is used to configure the pipes that are established