node.js fork函数并将parameter passing给subprocess

我创buildchlid进程时传递参数

if (cluster.isMaster) { for (var i = 0; i < os.cpus().length; i++) { var new_worker_env = {}; new_worker_env["WORKER_NAME"] = "worker" + i; var new_worker = cluster.fork(new_worker_env); } } 

然后尝试阅读它的孩子:

 if ( process.env["WORKER_NAME"] != undefined ) instance.name = process.env["WORKER_NAME"]; 

但是这个var不存在,为什么?

节点v0.8.8

       

网上收集的解决方案 "node.js fork函数并将parameter passing给subprocess"

似乎在Windows上为我工作,Node.js版本0.8.8

 var cluster = require('cluster'), os = require('os'); if (cluster.isMaster) { for (var i = 0; i < os.cpus().length; i++) { var new_worker_env = {}; new_worker_env["WORKER_NAME"] = "worker" + i; var new_worker = cluster.fork(new_worker_env); } } else { console.log(process.env['WORKER_NAME']); } 

输出:

 worker0 worker1