kill_port 0.1.10

Terminate processes by port cross-platform. 跨平台高效终止端口进程工具。
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::io;

use nix::{
  sys::signal::{Signal, kill},
  unistd::Pid,
};

pub(crate) fn kill_process(pid: u32, retry: u32) -> io::Result<()> {
  let signal = if retry > 10 {
    Signal::SIGKILL
  } else {
    Signal::SIGTERM
  };
  kill(Pid::from_raw(pid as i32), signal)
    .map_err(|err| io::Error::other(format!("kill process {pid} with {signal:?}: {err}")))
}