From 82d1024208e07bd4003f8f56f5b50e916f445afa Mon Sep 17 00:00:00 2001 From: Robert Jefe Lindstaedt Date: Tue, 5 Apr 2016 10:20:10 +0200 Subject: [PATCH] doc: describe child.kill() pitfalls on linux closes #2098 amend you reference --- doc/api/child_process.markdown | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/api/child_process.markdown b/doc/api/child_process.markdown index 5f17b435e6ea87..7020d15295d792 100644 --- a/doc/api/child_process.markdown +++ b/doc/api/child_process.markdown @@ -732,7 +732,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 @@ -998,4 +1020,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 \ No newline at end of file +[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify