node.js - Getting id of worker from inside worker process -
using node.js cluster module, straightforward id of worker process.
https://nodejs.org/api/cluster.html
that be:
cluster.on('fork', function (worker) { console.log('a worker', worker.id, 'was forked.'); });
but how can id
of worker inside worker itself? how come cluster module doesn't give worker id when cluster forks worker?
do have send worker it's cluster id master process?
i looking akin to:
process.id
(as opposed process.pid)
or
process.worker.id
in case, having trouble figuring out id of worker inside worker itself.
var cluster = require('cluster'); if (cluster.ismaster) { console.log('i master'); cluster.fork(); cluster.fork(); } else if (cluster.isworker) { console.log('i worker #' + cluster.worker.id); }
as in here
Comments
Post a Comment