Safely kill processes

This commit is contained in:
Jared Miller 2026-01-30 07:51:09 -05:00
parent 364e3d909e
commit 350c352989
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -148,13 +148,21 @@ async function main() {
process.stdin.resume(); process.stdin.resume();
if (pty) { if (pty) {
// Resume child process first // Resume child process first
try {
process.kill(pty.pid, "SIGCONT"); process.kill(pty.pid, "SIGCONT");
} catch {
// Child may have already exited
}
// Give child time to wake up, then trigger redraw // Give child time to wake up, then trigger redraw
setTimeout(() => { setTimeout(() => {
if (pty && !isExiting) { if (pty && !isExiting) {
const { cols, rows } = getTerminalSize(); const { cols, rows } = getTerminalSize();
pty.resize(cols, rows); pty.resize(cols, rows);
process.kill(pty.pid, "SIGWINCH"); // Tell child window changed try {
process.kill(pty.pid, "SIGWINCH");
} catch {
// Child may have already exited
}
} }
}, 50); }, 50);
} }
@ -187,7 +195,11 @@ async function main() {
process.stdin.setRawMode(false); process.stdin.setRawMode(false);
} }
if (pty) { if (pty) {
try {
process.kill(pty.pid, "SIGTSTP"); process.kill(pty.pid, "SIGTSTP");
} catch {
// Child may have already exited
}
} }
process.kill(process.pid, "SIGTSTP"); process.kill(process.pid, "SIGTSTP");
return; return;