GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: describe child.kill() pitfalls on linux · nodejs/node@59814ac

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • child_process.markdown
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.