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 59814ac

Browse filesBrowse files
eljefedelrodeodeljefeMyles Borins
authored andcommitted
doc: describe child.kill() pitfalls on linux
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 <benjamingr@gmail.com> Closes: #2098
1 parent 28040cc commit 59814ac
Copy full SHA for 59814ac

File tree

Expand file treeCollapse file tree

1 file changed

+24
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-2
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
+24-2Lines changed: 24 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,29 @@ delivered to that process instead which can have unexpected results.
750750
Note that while the function is called `kill`, the signal delivered to the
751751
child process may not actually terminate the process.
752752

753-
See `kill(2)`
753+
See `kill(2)` for reference.
754+
755+
Also note: on Linux, child processes of child processes will not be terminated
756+
when attempting to kill their parent. This is likely to happen when running a
757+
new process in a shell or with use of the `shell` option of `ChildProcess`, such
758+
as in this example:
759+
760+
```js
761+
'use strict';
762+
const spawn = require('child_process').spawn;
763+
764+
let child = spawn('sh', ['-c',
765+
`node -e "setInterval(() => {
766+
console.log(process.pid + 'is alive')
767+
}, 500);"`
768+
], {
769+
stdio: ['inherit', 'inherit', 'inherit']
770+
});
771+
772+
setTimeout(() => {
773+
child.kill(); // does not terminate the node process in the shell
774+
}, 2000);
775+
```
754776

755777
### child.pid
756778

@@ -1007,4 +1029,4 @@ to the same value.
10071029
[`options.stdio`]: #child_process_options_stdio
10081030
[`stdio`]: #child_process_options_stdio
10091031
[synchronous counterparts]: #child_process_synchronous_process_creation
1010-
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
1032+
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

0 commit comments

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