Last active
March 24, 2018 13:28
-
-
Save stevehorn/9292216931ced7a9bbe27c15657e2d7f to your computer and use it in GitHub Desktop.
Node fork example
This file contains hidden or 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
console.log(`CHILD process id: ${process.pid}`); | |
setTimeout(() => { | |
console.log('child timeout'); | |
}, 5000); |
This file contains hidden or 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
const cp = require('child_process'); | |
console.log(`PARENT process id: ${process.pid}`); | |
setInterval(() => { | |
const childFork = cp.fork(`${__dirname}/child.js`); | |
childFork.on('exit', (m) => { | |
console.log('PARENT got exit'); | |
childFork.kill(); | |
}); | |
}, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment