diff options
| author | Jeremy Smart <jeremy3141592@gmail.com> | 2025-06-18 00:38:55 -0400 |
|---|---|---|
| committer | Jeremy Smart <jeremy3141592@gmail.com> | 2025-06-18 00:38:55 -0400 |
| commit | b3914945ae2d77770c25ed124a8450d82c8f7fe9 (patch) | |
| tree | b32400be050f376eecdb4546724fd6cea64e0051 /library/std/src/sys/process/unix/unix.rs | |
| parent | a124fb3cb7291d75872934f411d81fe298379ace (diff) | |
| download | rust-b3914945ae2d77770c25ed124a8450d82c8f7fe9.tar.gz rust-b3914945ae2d77770c25ed124a8450d82c8f7fe9.zip | |
add ChildExt(::send_signal)
Diffstat (limited to 'library/std/src/sys/process/unix/unix.rs')
| -rw-r--r-- | library/std/src/sys/process/unix/unix.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 4f595ac9a1c..1fe80c13b81 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -963,9 +963,13 @@ impl Process { self.pid as u32 } - pub fn kill(&mut self) -> io::Result<()> { + pub fn kill(&self) -> io::Result<()> { + self.send_signal(libc::SIGKILL) + } + + pub(crate) fn send_signal(&self, signal: i32) -> io::Result<()> { // If we've already waited on this process then the pid can be recycled - // and used for another process, and we probably shouldn't be killing + // and used for another process, and we probably shouldn't be signaling // random processes, so return Ok because the process has exited already. if self.status.is_some() { return Ok(()); @@ -973,9 +977,9 @@ impl Process { #[cfg(target_os = "linux")] if let Some(pid_fd) = self.pidfd.as_ref() { // pidfd_send_signal predates pidfd_open. so if we were able to get an fd then sending signals will work too - return pid_fd.kill(); + return pid_fd.send_signal(signal); } - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) + cvt(unsafe { libc::kill(self.pid, signal) }).map(drop) } pub fn wait(&mut self) -> io::Result<ExitStatus> { |
