From 2f762eee4bebed1210680c0ffbd2d242016ca297 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 27 Mar 2026 00:14:52 -0700 Subject: [PATCH] Avoid killing Zed when terminating terminal process before process group is set by shell (#52542) Release Notes: - Fixed a bug where killing a terminal process in the agent panel would sometimes kill Zed itself. --- crates/terminal/src/pty_info.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/terminal/src/pty_info.rs b/crates/terminal/src/pty_info.rs index 2663095c52f386cfd9528f1c96fa32a39abd9a59..7b6676760ca61c1cfde22601d0c0eb0b9641b42a 100644 --- a/crates/terminal/src/pty_info.rs +++ b/crates/terminal/src/pty_info.rs @@ -36,11 +36,19 @@ impl ProcessIdGetter { } fn pid(&self) -> Option { + // Negative pid means error. + // Zero pid means no foreground process group is set on the PTY yet. + // Avoid killing the current process by returning a zero pid. let pid = unsafe { libc::tcgetpgrp(self.handle) }; - if pid < 0 { + if pid > 0 { + return Some(Pid::from_u32(pid as u32)); + } + + if self.fallback_pid > 0 { return Some(Pid::from_u32(self.fallback_pid)); } - Some(Pid::from_u32(pid as u32)) + + None } }