简体   繁体   中英

How to fork/clone an identical Node child process in the same sense as fork() of Linux system call?

So I was developing a server farm on Node which requires multiple processes per machine to handle the load. Since Windows doesn't quite get along with Node cluster module, I had to manually work it out.

The real problem is when I was forking Node processes, a JS module path was required as the first argument to the child_process.fork() function and once forked, the child process wouldn't inherit anything from its parent. In my case, I want a function that does similar thing as fork() system call in Linux, which clones the parent process, inherits everything and continues execution from exactly where the fork() is done. Can this be achieved on the Node platform?

I don't think node.js is ever going to support fork(2)

The comment from the node github page on the subject

https://github.com/joyent/node/issues/2334#issuecomment-3153822

We're not (ever) going to support fork.

not portable to windows

difficult conceptually for users

entire heap will be quickly copied with a compacting VM; no benefits from copy-on-write

not necessary

difficult for us to do

child_process.fork()

This is a special case of the spawn() functionality for spawning Node processes. In addition to having all the methods in a normal ChildProcess instance, the returned object has a communication channel built-in. See child.send(message, [sendHandle]) for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM