0

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.

asked Oct 14, 2015 at 7:42

1 Answer 1

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.

answered Oct 29, 2015 at 18:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.