Skip to content

Instantly share code, notes, and snippets.

@limianwang
Created December 2, 2014 16:41
Show Gist options
  • Save limianwang/55e8a0b6ca816e024358 to your computer and use it in GitHub Desktop.
Save limianwang/55e8a0b6ca816e024358 to your computer and use it in GitHub Desktop.
cluster
'use strict';
var cluster = require('cluster');
if(cluster.isMaster) {
console.log('master', process.pid);
var worker = cluster.fork();
console.log('forked child pid: ', worker.process.pid);
} else {
console.log('child', process.pid);
}
/*
$ node foo.js
master 36520
forked child pid: 36521
child 36521
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment