真正的问题是当我分配节点进程时,需要一个JS模块路径作为child_process.fork()函数的第一个参数,并且一旦分叉,子进程就不会从其父进程继承任何东西.在我的例子中,我想要一个与Linux中的fork()系统调用类似的函数,该函数克隆父进程,继承所有内容并从fork()的确切位置继续执行.这可以在Node平台上实现吗?
我不认为node.js会支持 fork(2)关于该主题的节点github页面的注释
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.