Return Ok on kill if process has already exited

This commit is contained in:
Chris Denton
2023-06-13 20:32:31 +01:00
parent 2ca8d358e5
commit e7fda447e7
4 changed files with 17 additions and 14 deletions

View File

@@ -719,12 +719,9 @@ impl Process {
pub fn kill(&mut self) -> 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
// random processes, so just return an error.
// random processes, so return Ok because the process has exited already.
if self.status.is_some() {
Err(io::const_io_error!(
ErrorKind::InvalidInput,
"invalid argument: can't kill an exited process",
))
Ok(())
} else {
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop)
}