Skip to content

Instantly share code, notes, and snippets.

@stevehorn
Last active March 24, 2018 13:28
Show Gist options
  • Save stevehorn/9292216931ced7a9bbe27c15657e2d7f to your computer and use it in GitHub Desktop.
Save stevehorn/9292216931ced7a9bbe27c15657e2d7f to your computer and use it in GitHub Desktop.
Node fork example
console.log(`CHILD process id: ${process.pid}`);
setTimeout(() => {
console.log('child timeout');
}, 5000);
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