Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created July 30, 2012 20:01
Show Gist options
  • Save cowboy/3209657 to your computer and use it in GitHub Desktop.
Save cowboy/3209657 to your computer and use it in GitHub Desktop.
Node.js 0.8: trying to see a difference between child_process "exit" and "close" events
function parent() {
var n = 0;
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [module.filename, true]);
child.stdout.on('data', function(buf) {
n += String(buf).length;
});
child.on('exit', function() {
console.log('exit', n);
});
child.on('close', function() {
console.log('close', n);
});
}
function child() {
var n = 0
var id = setInterval(function() {
if (++n > 1000) {
clearInterval(id);
} else {
process.stdout.write(Array(100001).join(1234567890));
}
}, 1);
}
if (process.argv[2]) {
child();
} else {
parent();
}
@cowboy
Copy link
Author

cowboy commented Jul 30, 2012

Can't get it to be different. Meh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment