Last active
December 26, 2015 04:39
-
-
Save dstibrany/7094835 to your computer and use it in GitHub Desktop.
This file contains 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'); | |
var http = require('http'); | |
var cp = require('child_process'); | |
if (cluster.isMaster) { | |
var worker = cluster.fork(); | |
} | |
else { | |
server = http.createServer(); // number of servers is arbitrary | |
server2 = http.createServer(); | |
server.listen(10011, 'localhost') | |
server2.listen(10012, 'localhost') | |
setTimeout(run, 100); // need this timeout to recreate | |
} | |
function run() { | |
var sleep = cp.spawn('sleep', ['7']); | |
var lsof = cp.spawn('lsof', ['-p', sleep.pid]); | |
var grep = cp.spawn('grep', ['LISTEN']); | |
lsof.stdout.on('data', function(data) { | |
grep.stdin.write(data); | |
}); | |
lsof.on('close', function() { | |
grep.stdin.end(); | |
}); | |
grep.stdout.on('data', function(data) { | |
console.log(data.toString()); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output is (roughly)
sleep 46028 dstibrany 11u IPv4 0x28b8ad9c32befc2d 0t0 TCP localhost:10011 (LISTEN)
sleep 46028 dstibrany 13u IPv4 0x28b8ad9c350db37d 0t0 TCP localhost:10012 (LISTEN)