1

With regard to a child process in Node.js that is created like so:

var cp = require('child_process');
var n = cp.fork('child.js');

When forking a child_process with Node.js is it proper to kill the child process when it's done with it's work?

At the moment my guess is that if you don't kill the process that it stays idle and just uses up resources unnecessarily, but I am not clear on this.

2

You can either exit from inside the child process using process.exit(0) (note that 0 can be replaced with other code), or you can kill it from the parent process, in your example n.kill();

I assume you would want to kill it from inside the script, since there you would have the context to know when the job is done.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.