-
-
Save aberant/2028935 to your computer and use it in GitHub Desktop.
A child sending a message to its parent.
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 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) | |
}); | |
} |
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
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