Skip to content

Instantly share code, notes, and snippets.

@hraban
Created November 22, 2018 17:26
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 hraban/b2f5870bd20f876ac74fe89f99f0ecba to your computer and use it in GitHub Desktop.
Save hraban/b2f5870bd20f876ac74fe89f99f0ecba to your computer and use it in GitHub Desktop.
child process interruption and signal control
const child_process = require('child_process');
const process = require('process');
process.on('SIGINT', () => console.log("ooh this is sigint"));
process.on('SIGUSR1', () => console.log("oh this is sigusr1!!"));
function block4ever() {
setTimeout(() => {} , 1000000);
}
function spawntalker(message) {
child_process.fork('./talk4ever.js', ['hi there']);
}
function main() {
spawntalker();
block4ever();
}
main();
const process = require('process');
function monitorPpid() {
setInterval(() => {
if (process.ppid == 1) {
console.log('talk4ever.js parent process died, quitting.');
process.exit(0);
}
}, 1000);
}
function main() {
monitorPpid();
setInterval(() => console.log(process.argv[2] || 'hello'), 2000);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment