Skip to content

Instantly share code, notes, and snippets.

@hraban hraban/main.js
Created Nov 22, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.