Created
January 7, 2013 06:19
-
-
Save erhangundogan/4472898 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
// child.js | |
console.log('child was created with PID: ' + process.pid); | |
process.on('exit', function(code,signal) { | |
console.warn('child is exiting with code: '+ code +' and signal: '+signal) | |
}); | |
process.on('message', function(data) { | |
console.log('child: got message from parent: ' + data); | |
process.send('hi, thanks for the message!'); | |
}); | |
// fork.js | |
var fork = require('child_process').fork, | |
child = fork(__dirname + '/child.js'); | |
child.on('message', function(data) { | |
console.log('parent: got message from child: ' + data); | |
}); | |
child.send('hello from your parent'); | |
// server.js | |
function format(type, output) { | |
console.log('child says (' + type + '): ' + output); | |
} | |
var spawn = require('child_process').spawn, | |
child = spawn('node',['child.js']); | |
child.stdout.on('data', format.bind(global,'stdout')); | |
child.stderr.on('data', format.bind(global,'stderr')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment