1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::io;
use std::process::Command;
#[cfg(unix)]
pub fn kill_process(pid: u32) -> io::Result<()> {
let status = Command::new("kill")
.arg("-15") .arg(pid.to_string())
.status()?;
if !status.success() {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to kill process {}", pid),
));
}
Ok(())
}
#[cfg(windows)]
pub fn kill_process(pid: u32) -> io::Result<()> {
let status = Command::new("taskkill")
.arg("/PID")
.arg(pid.to_string())
.status()?;
if !status.success() {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to kill process {}", pid),
));
}
Ok(())
}