Created
July 15, 2015 15:33
-
-
Save DavidBruant/44792e25e1fb1dcb4cb8 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
"use strict"; | |
process.title = "child 1" | |
var fs = require('fs') | |
var writeStream = fs.createWriteStream(undefined, {fd: 3}); | |
console.log('Child 1!', typeof readStream, typeof writeStream); | |
setInterval(function(){ | |
console.log('child ping'); | |
writeStream.write("ping"); | |
}, 600); | |
setTimeout(function(){ | |
console.log('child 1 out') | |
process.exit(); | |
}, 5*1000); | |
process.on('uncaughtException', function(err){ | |
console.error('child', 1, err, err.stack) | |
}); |
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
"use strict"; | |
process.title = "child 2"; | |
var fs = require('fs') | |
var readStream = fs.createReadStream(undefined, {fd: 3}); | |
console.log('Child 2!', typeof readStream, typeof writeStream); | |
readStream.on('error', function(err){ | |
console.log("readStream error", err); | |
}); | |
readStream.on('close', function(err){ | |
console.log("c2 readStream close", err); | |
}); | |
readStream.on('end', function(err){ | |
console.log("c2 readStream end", err); | |
}); | |
readStream.on('readable', function(){ | |
readStream.on('data', function(buf){ | |
console.log('child 2 received', buf.length); | |
}); | |
}); | |
setTimeout(function(){ | |
console.log('child 2 out') | |
process.exit(); | |
}, 5*1000); | |
process.on('uncaughtException', function(err){ | |
console.error('child', 2, err, err.stack) | |
}); |
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
"use strict"; | |
var spawn = require('child_process').spawn; | |
var child1 = spawn("node", [require.resolve('./child1.js')], { | |
stdio: [process.stdin, process.stdout, process.stderr, 'pipe'] | |
}); | |
var child2 = spawn("node", [require.resolve('./child2.js')], { | |
stdio: [process.stdin, process.stdout, process.stderr, child1.stdio[3]] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment