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?
Duplicate of https://github.com/nodejs/node/issues/13538?
@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.
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.