Home > Back-end >  Are forked processes garbage collected by deleting their reference objects?
Are forked processes garbage collected by deleting their reference objects?

Time:12-09

I have a service that needs to keep multiple forked processes in a round robin. When I am done with one process, I do not call child.kill(), instead I simply shift an array (delete the reference object) that contains the child objects.

uses node v11.0.0

const children = [
  child_process.fork('../script.js'),
  child_process.fork('../script.js')
];

console.log(
  children.map(c => c.connected)
); // [true, true]

child.shift();

console.log(
  children.map(c => c.connected)
); // [true]

After shifting, is the deleted child process completely garbage collected by the parent process?

CodePudding user response:

After shifting, is the deleted child process completely garbage collected by the parent process?

No. A child process is an OS level thing, not a Javascript thing. It won't be affected by garbage collection in the way you describe. If you mean for the child to exit, you need to either kill it or send it a message telling it to exit.

  • Related