Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: refine child_process detach behaviour #5330

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions doc/api/child_process.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down