Skip to content

Instantly share code, notes, and snippets.

@motemen
Created April 26, 2016 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motemen/07e1feb114d7fe7cd8e4fab7052db082 to your computer and use it in GitHub Desktop.
Save motemen/07e1feb114d7fe7cd8e4fab7052db082 to your computer and use it in GitHub Desktop.
var spawn = require('child_process').spawn;
var depth = process.argv[2];
if (!depth) {
var p = spawn('node', [ process.argv[1], '1' ], { stdio: 'inherit' });
setTimeout(() => {
console.log(process.pid, 'Killing child', p.pid);
p.kill();
}, 500);
} else if (depth === '1') {
console.log(process.pid, 'Hello from child');
spawn('node', [ process.argv[1], '2' ], { stdio: 'inherit' });
} else if (depth === '2') {
console.log(process.pid, 'Hello from grand child');
setTimeout(() => { console.log(process.pid, '!!! Want not to be printed') }, 2 * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment