How to prevent disconnection of child processes of a node from a parent process of a node?

I use child_process.spawn / child_process.fork to start multiple child processes from a node.js application. When the parent process is stopped using Ctrl-C, the child processes also stop. Is there an elegant way to support child processes?

+4
source share
2 answers

You can try to catch SIGINT in your child:

 // child.js process.on("SIGINT", function() { console.log("sigint caught") }); // parent.js var fork = require("child_process").fork, child = fork(__dirname + "/child.js"); 

Run parent.js and hit ^C Your child.js should continue to run in the background. I do not know what the consequences of this will be during the life of child.js .

Here's an enlightening, albeit fairly old, discussion on a topic on the node.js mailing list .

+3
source

You can call childprocess.disconnect(); in parent or process.disconnect(); in the child.

-one
source

Source: https://habr.com/ru/post/1396839/


All Articles