所以我在Node上开发一个服务器场,每个机器需要多个进程来处理负载.由于
Windows与Node集群模块不太相配,我不得不手动完成它.
真正的问题是当我分配节点进程时,需要一个JS模块路径作为child_process.fork()函数的第一个参数,并且一旦分叉,子进程就不会从其父进程继承任何东西.在我的例子中,我想要一个与Linux中的fork()系统调用类似的函数,该函数克隆父进程,继承所有内容并从fork()的确切位置继续执行.这可以在Node平台上实现吗?
解决方法
我不认为node.js会支持
fork(2)
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
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.