![](/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.