![](/img/trans.png)
[英]Why is Node.js cluster.fork() not creating copies of my process on Windows 8?
[英]Node.js - cluster.fork() - how to check number of worker within the worker?
使用cluster.fork
时,有没有办法检查创建的worker
在工作人员本身内的编号?
if(cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
// Fork workers
for (let i = 0; i < cores.length; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
}
else{
var number = CLUSTER_NUM; //Get the spawned number of the worker
}
cluster.worker.id应该是一个递增的数字。
if (cluster.isWorker) {
console.log(cluster.worker.id); // 0, 1, 2 etc.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.