Created
September 22, 2015 14:54
-
-
Save ilkovich/a4f11be91984c5f5f0ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = require('cluster') | |
| , worker | |
| , http = require('http') | |
| ; | |
| function log(msg) { | |
| process.stdout.write(msg); | |
| } | |
| if(cluster.isMaster) { | |
| cluster.setupMaster({ silent: true }); // Keep cluster from automatically grabbing stdin/out/err | |
| cluster.fork(); | |
| cluster.on('fork', function(worker) { | |
| worker.process.stdout.on('data', function(chunk) { | |
| log('out: '+chunk); | |
| }); | |
| worker.process.stderr.on('data', function(chunk) { | |
| log('err: '+chunk); | |
| }); | |
| }); | |
| //arbitrarily keep the master process open. | |
| http.createServer(function(req, res) { | |
| res.writeHead(200); | |
| res.end("hello world\n"); | |
| }).listen(8000); | |
| } else { | |
| for(var i=0; i<100; i++) { | |
| if(Math.random()*100 < i) | |
| console.log(i); | |
| else | |
| console.error(i); | |
| } | |
| process.exit(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment