I pass arguments when create chlid-processes
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);
}
}
and then try to read it in childs:
if ( process.env["WORKER_NAME"] != undefined ) instance.name = process.env["WORKER_NAME"];
but this var isn't exist, why?
Node v0.8.8
Seems to work for me on Windows, Node.js version 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']);
}
outputs:
worker0
worker1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With