Skip to content

Commit

Permalink
Simulate Ctrl-C through pty to send SIGINT to process group
Browse files Browse the repository at this point in the history
  • Loading branch information
layerssss committed Oct 31, 2018
1 parent 0b2b3a5 commit 6d8bc78
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/localhostd.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class LocalhostD {

terminal.pty.on("exit", code =>
this._triggerAsync(async () => {
this._debug("terminal", `exit: ${code}`);
if (terminal.outStream) terminal.outStream.end();
delete this._terminals[application.name];

Expand Down Expand Up @@ -373,15 +374,20 @@ class LocalhostD {
let applicationDown = false;
const terminal = this._terminals[application.name];
if (terminal) {
terminal.pty.write("\u0003");

if (Os.platform() === "win32") {
terminal.pty.kill();
this._debug("stop", "kill()");
} else {
terminal.pty.kill("SIGINT");
this._debug("stop", "SIGINT");
}

this._triggerAsync(async () => {
await sleep(10000);
if (applicationDown) return;
this._debug("stop", "SIGKILL");
terminal.pty.kill("SIGKILL");
});
}
Expand Down

0 comments on commit 6d8bc78

Please sign in to comment.