如何在node.js中分叉self?
我想在nodejs app.js的一开始就创建一个新流程,然后在主流程中创建一个http服务器,在新流程中,我将运行如何在node.js中分叉self?,node.js,Node.js,我想在nodejs app.js的一开始就创建一个新流程,然后在主流程中创建一个http服务器,在新流程中,我将运行while true循环来完成一些工作 我读过child\u process.fork(modulePath,…),它需要一个modulePath,在我的情况下,我只需要在C 大概是这样的: // very begin of the server.js fork(function(new_process) { // child process while(true) {
while true
循环来完成一些工作
我读过child\u process.fork(modulePath,…)
,它需要一个modulePath
,在我的情况下,我只需要在C
大概是这样的:
// very begin of the server.js
fork(function(new_process) {
// child process
while(true) {
//do sth
}
});
// main process
// balabala
server.listen(3000, function () {
console.log('Express server listening on port 3000');
});
正如您所发现的,“fork”的名称很糟糕:它实际上是一个fork/exec
你可能想考虑以下任何一个选项:
您也可以考虑NoDE.JS集群: