Last active
November 3, 2020 16:38
-
-
Save ayal/a27ce413088393ce26ead3ed0a96765b to your computer and use it in GitHub Desktop.
killing forked children after setrawmode(true -> false)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cp = require("child_process"); | |
console.log('hi from child', process.stdin.isRaw) | |
setInterval(() => { | |
console.log('hi from child', process.stdin.isRaw); | |
}, 1000); | |
var child2 = cp.fork('child2.js', []); | |
console.log('child 2 pid', child2.pid); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('2 hi from child 2', process.stdin.isRaw) | |
var handle = setInterval(() => { | |
console.log('2 hi from child 2', process.stdin.isRaw); | |
}, 1000); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('start parent'); | |
var cp = require("child_process"); | |
process.stdin.setRawMode(true); | |
process.stdin.setEncoding('utf8'); | |
const CTRL_C = '\u0003'; | |
console.log('HAY parent', process.stdin.isRaw, process.stdin.isTTY); | |
var handler = (str) => { | |
console.log('a keypress!'); | |
if (str === CTRL_C) { | |
console.log('press ctrl c again to exit'); | |
process.stdin.setRawMode(false); | |
} | |
} | |
process.stdin.on('data', handler) | |
process.on('SIGINT', ()=>{ | |
process.stdin.emit('end') // without this terminal might wont be responsive to ctrl+c after exit | |
process.exit(); | |
}) | |
var child = cp.fork('child.js', []); | |
console.log('child pid', child.pid); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment