diff options
Diffstat (limited to 'makima/src/daemon/process/claude.rs')
| -rw-r--r-- | makima/src/daemon/process/claude.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/makima/src/daemon/process/claude.rs b/makima/src/daemon/process/claude.rs index 93b097c..536d883 100644 --- a/makima/src/daemon/process/claude.rs +++ b/makima/src/daemon/process/claude.rs @@ -102,12 +102,45 @@ impl ClaudeProcess { } } - /// Kill the process. + /// Kill the process (SIGKILL). pub async fn kill(&mut self) -> Result<(), ClaudeProcessError> { self.child.kill().await?; Ok(()) } + /// Get the process ID, if the process is still running. + pub fn id(&self) -> Option<u32> { + self.child.id() + } + + /// Send SIGTERM to gracefully terminate the process (Unix only). + /// Returns Ok(true) if signal was sent, Ok(false) if process already exited. + #[cfg(unix)] + pub fn terminate(&self) -> Result<bool, ClaudeProcessError> { + use nix::sys::signal::{kill, Signal}; + use nix::unistd::Pid; + + if let Some(pid) = self.child.id() { + match kill(Pid::from_raw(pid as i32), Signal::SIGTERM) { + Ok(()) => Ok(true), + Err(nix::errno::Errno::ESRCH) => Ok(false), // Process doesn't exist + Err(e) => Err(ClaudeProcessError::OutputRead(format!( + "Failed to send SIGTERM: {}", + e + ))), + } + } else { + Ok(false) // Process already exited + } + } + + /// Send SIGTERM to gracefully terminate the process (no-op on non-Unix). + #[cfg(not(unix))] + pub fn terminate(&self) -> Result<bool, ClaudeProcessError> { + // On non-Unix platforms, fall back to kill + Ok(false) + } + /// Get the next output line, if available. pub async fn next_output(&mut self) -> Option<OutputLine> { self.output_rx.recv().await |
