close chidl processes when parent exits

This commit is contained in:
Jan Prochazka
2020-05-01 09:35:57 +02:00
parent 17134552ce
commit 933f29afda
9 changed files with 39 additions and 4 deletions

View File

@@ -0,0 +1,17 @@
let counter = 0;
function childProcessChecker() {
setInterval(() => {
try {
process.send({ msgtype: 'ping', counter: counter++ });
} catch (ex) {
// This will come once parent dies.
// One way can be to check for error code ERR_IPC_CHANNEL_CLOSED
// and call process.exit()
console.log('parent died', ex.toString());
process.exit();
}
}, 1000);
}
module.exports = childProcessChecker;