I have this function and fork a child process to run a heavy work on background. The work
module sends message after it completes the work. How do I kill or close the forked process?
function doWork() {
var child = cp.fork(__dirname + '/work');
child.on('message', function(m) {
console.log('completed: ' + m);
// try to kill child process when work signals it's done
child.kill('SIGHUP');
});
child.send({
msg: 'do work',
name: self.myname
});
}
-edit-
I tried child.kill('SIGHUP')
and child.kill();
when work signals it's done. I seems didn't kill the process. If I do ps | grep node
, it still shows the work process is alive. What am I missing?