Skip to content

Commit

Permalink
doc: describe child.kill() pitfalls on linux
Browse files Browse the repository at this point in the history
This commit refines the documentation around child.kill(), where kill
attempts against shells will lead to unexpected results. Namely, on
linux the child process of a child process will not terminate, when
its parent gets terminated. This is different across the the
platforms.

PR-URL: #2098
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Closes: #2098
  • Loading branch information
eljefedelrodeodeljefe authored and benjamingr committed Apr 10, 2016
1 parent 6222e5b commit 8f4fdc9
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions doc/api/child_process.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,29 @@ delivered to that process instead which can have unexpected results.
Note that while the function is called `kill`, the signal delivered to the
child process may not actually terminate the process.

See `kill(2)`
See `kill(2)` for reference.

Also note: on Linux, child processes of child processes will not be terminated
when attempting to kill their parent. This is likely to happen when running a
new process in a shell or with use of the `shell` option of `ChildProcess`, such
as in this example:

```js
'use strict';
const spawn = require('child_process').spawn;

let child = spawn('sh', ['-c',
`node -e "setInterval(() => {
console.log(process.pid + 'is alive')
}, 500);"`
], {
stdio: ['inherit', 'inherit', 'inherit']
});

setTimeout(() => {
child.kill(); // does not terminate the node process in the shell
}, 2000);
```

### child.pid

Expand Down Expand Up @@ -1025,4 +1047,4 @@ to the same value.
[`options.stdio`]: #child_process_options_stdio
[`stdio`]: #child_process_options_stdio
[synchronous counterparts]: #child_process_synchronous_process_creation
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

3 comments on commit 8f4fdc9

@stevemao
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"PR-URL:" is wrong. It should be #6052

@benjamingr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry :( It got copied from the closes part. I'll see if I can edit it retroactively in the next commit I land.

@mscdex
Copy link
Contributor

@mscdex mscdex commented on 8f4fdc9 Apr 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjamingr I wouldn't force push at this point, too much time has passed

Please sign in to comment.