title: Node.js cluster get master PID
body: <p>I used following cluster code to fork multiple process for my node app.</p>
  
  <pre><code>if (cluster.isMaster) {
    require('os').cpus().forEach(function () {
      cluster.fork();
    });
  
    cluster.on('exit', function (worker, code, signal) {
      cluster.fork();
    });
  } else if (cluster.isWorker) {
    logger.log.info('Worker server started on port %d (ID: %d, PID: %d)', app.get('port'), cluster.worker.id, cluster.worker.process.pid);
  }
  </code></pre>
  
  <p>the output is:</p>
  
  <pre><code>Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 1, PID: 606)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 2, PID: 607)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 5, PID: 610)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 3, PID: 608)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 4, PID: 609)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 6, PID: 611)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 8, PID: 613)
  Thu Sep 05 2013 20:30:03 GMT-0700 (PDT) - info: Worker server started on port 3000 (ID: 7, PID: 612)
  </code></pre>
  
  <p>There is 8 worker processes but when I checked process using pgrep, I saw 9</p>
  
  <pre><code>$ pgrep -l node
  613 node
  612 node
  611 node
  610 node
  609 node
  608 node
  607 node
  606 node
  605 node
  </code></pre>
  
  <p>so one process extra must be master process and how do I print out the master process IP?</p>
  
  <p>Thanks</p>
  
  <p>I posted another question related to this one, I think it's might be useful for everyone to look at this as well:</p>
  
  <p><a href="https://stackoverflow.com/questions/18650527/node-js-cluster-master-process-reboot-after-got-kill-pgrep">Node.js cluster master process reboot after got kill &amp; pgrep?</a></p>