Skip to content

Commit

Permalink
Have terminalProcesses kill themselves when their parent is killed
Browse files Browse the repository at this point in the history
Fixes #7458
  • Loading branch information
Tyriar committed Jun 9, 2016
1 parent 2386b26 commit 009ee1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class TerminalInstance {

private createTerminalProcess(): cp.ChildProcess {
let env = this.cloneEnv();
env['PTYPID'] = process.pid.toString();
env['PTYSHELL'] = this.shell.executable;
this.shell.args.forEach((arg, i) => {
env[`PTYSHELLARG${i}`] = arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ process.on('message', function (message) {
}
});

setupPlanB(process.env.PTYPID);

function getArgs() {
var args = [];
var i = 0;
Expand All @@ -38,4 +40,14 @@ function getArgs() {
i++;
}
return args;
}

function setupPlanB(parentPid) {
setInterval(function () {
try {
process.kill(parentPid, 0); // throws an exception if the main process doesn't exist anymore.
} catch (e) {
process.exit();
}
}, 5000);
}

0 comments on commit 009ee1a

Please sign in to comment.