Kill the process. # Errors Returns an error if the process cannot be killed.
(&mut self)
| 755 | /// |
| 756 | /// Returns an error if the process cannot be killed. |
| 757 | pub fn kill(&mut self) -> Result<()> { |
| 758 | // First try SIGTERM |
| 759 | if let Err(e) = self.signal(Signal::SIGTERM) { |
| 760 | openshell_ocsf::ocsf_emit!( |
| 761 | openshell_ocsf::ProcessActivityBuilder::new(openshell_ocsf::ctx::ctx()) |
| 762 | .activity(openshell_ocsf::ActivityId::Close) |
| 763 | .severity(openshell_ocsf::SeverityId::Medium) |
| 764 | .status(openshell_ocsf::StatusId::Failure) |
| 765 | .message(format!("Failed to send SIGTERM: {e}")) |
| 766 | .build() |
| 767 | ); |
| 768 | } |
| 769 | |
| 770 | // Give the process a moment to terminate gracefully |
| 771 | std::thread::sleep(std::time::Duration::from_millis(100)); |
| 772 | |
| 773 | // Force kill if still running |
| 774 | if let Some(id) = self.child.id() { |
| 775 | debug!(pid = id, "Sending SIGKILL"); |
| 776 | let pid = i32::try_from(id).unwrap_or(i32::MAX); |
| 777 | let _ = signal::kill(Pid::from_raw(pid), Signal::SIGKILL); |
| 778 | } |
| 779 | |
| 780 | Ok(()) |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | impl Drop for ProcessHandle { |