Skip to content

process/child_process: be able to kill all descendent processes for a given process. #40438

Description

@tony-go

Hi 👋,

Hope everyone is doing great.

Is your feature request related to a problem? Please describe.
I used require("child_process").spawn recently with the option shell: true.

I observe in this case that two processes are spawned on for the shell itself and another one for the current command spawned by the shell.

So when I use ChildProcess.kill(), it kills the shell process but not its child (descendent processes). (In my case the child process is an HTTP server, so a long process that doesn't exist itself")

Describe the solution you'd like
I thought about two different APIs:

  • First one (with the ChildProcess)
const { spawn } = require("child_process");

const p1 = spawn(httpServerCommand, { shell: true });

p1.killDeep();
  • Second one (with process)
const { spawn } = require("child_process");

const p1 = spawn(httpServerCommand, { shell: true });

process.killDeep(p1.pid);

In both cases killDeep will kill all the descendent processes.

Describe alternatives you've considered
I used this library: https://www.npmjs.com/package/tree-kill

I'm sorry in advance if I miss something in the documentation (But I promise that I tried ahahah)

If this feature request is acceptable, I could help and contribute (with a bit of guidance ^^)

Thanks for reading me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.feature requestIssues that request new features to be added to Node.js.processIssues and PRs related to the process subsystem.stale

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions