Node: non-detached process fails to be killed by parent on exit

Created on 31 Jul 2017  路  7Comments  路  Source: nodejs/node

This is a question disguised as a bug report. Lol just kidding, it really could be a bug.

So I start a child process with detached set explicitly to false.

When the parent exits, the child is still running. I believe what happened is that parent was not able to kill the child before exiting (this seems obvious...or is it?).

Does the parent not send a SIGKILL signal to the child? Only SIGINT? Is it expected that in some cases the parent cannot kill the child even when detached is set explicitly to false?

question

Most helpful comment

Processes aren't killed unless you send them a signal that they don't or can't handle.

If you ^C a process, the kernel sends a SIGINT to the process group; that usually terminates both the parent and its children, grandchildren, and so on.

If the parent simply exits, its descendants are reparented by the kernel to their grandparent (the parent's parent), all the way up to PID 1 if need be.

All 7 comments

@mscdex not sure if it's a duplicate or not. After reading that issue, I am more confused. I expected that a Node.js parent process which spawned a child process of any flavor would send the child a SIGTERM or SIGINT signal upon exit, but I guess not? In my case, I am not sure if there is an applicable grandparent process here. Or maybe all *nix processes have grandparents, not sure.

All processes at least spawn from the init process, so there should always be a grandparent on *nix.

@mscdex yeah that makes sense - but still looking to the mechanism that actually is responsible for killing child processes if detached is false.

Seems like this has been answered. Closing then.

@bnoordhuis do you know the mechanism by which a node child process is killed if detached is set to false and the parent dies?

Processes aren't killed unless you send them a signal that they don't or can't handle.

If you ^C a process, the kernel sends a SIGINT to the process group; that usually terminates both the parent and its children, grandchildren, and so on.

If the parent simply exits, its descendants are reparented by the kernel to their grandparent (the parent's parent), all the way up to PID 1 if need be.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenvachon picture stevenvachon  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

akdor1154 picture akdor1154  路  3Comments

seishun picture seishun  路  3Comments

mcollina picture mcollina  路  3Comments