Skip to content

Instantly share code, notes, and snippets.

@aberant
Forked from redsquirrel/gist:2025533
Created March 13, 2012 13:58
Show Gist options
  • Save aberant/2028935 to your computer and use it in GitHub Desktop.
Save aberant/2028935 to your computer and use it in GitHub Desktop.
A child sending a message to its parent.
var fork = require('child_process').fork;
if (process.argv[2] == 'son') {
setTimeout(function() {
process.send({ result: 'hi dad' });
process.exit(0);
}, 1000);
} else {
var child = fork(__filename, [ 'son' ]);
child.on('message', function(m) {
console.log(m.result)
});
}
pid = fork {
puts "hi dad"
sleep 1
}
# Waits for any child whose process group ID equals that of the calling process.
Process.waitpid(pid, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment