Skip to content

What is the correct way to kill a child process? #1389

@johnsoncodehk

Description

@johnsoncodehk
  • Node.js Version: 9.7.1
  • OS: linux
  • Scope: runtime
  • Module: child_process

I used child_process.fork to generate some child processes and kill them with child.kill() when the work is done.
My system always throws errors after running for a while. After some troubleshooting, I found that the longer my system is running, the more zombie processes are generated. The ppids of these processes are all 1, because child.kill() does not release the process from memory, just stops the process.

I read the documentation and found that this is the mechanism of the Linux system. The killed process needs to call wait/waitpid to wait for the process to finish, but wait/waitpid does not exist in child_process and node.

I found a lot of information, but I didn't find a way for me.
I guess this is a wide-ranging problem. The solution should not be difficult. Have I missed something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions