1#[cfg(unix)]
2pub fn send_sigterm_to_self() {
3 use libc::{SIGTERM, kill};
4 let pid = std::process::id() as i32;
5 println!("Unix: sending SIGTERM to self (pid={})", pid);
6 unsafe {
7 kill(pid, SIGTERM);
8 }
9}
10
11#[cfg(windows)]
12pub fn send_sigterm_to_self() {
13 use windows_sys::Win32::System::Threading::PROCESS_TERMINATE;
14 use windows_sys::Win32::System::Threading::{OpenProcess, TerminateProcess};
15
16 let pid = std::process::id();
17 println!("Windows: terminating self (pid={})", pid);
18
19 unsafe {
20 let handle = OpenProcess(PROCESS_TERMINATE, 0, pid);
21 if handle != 0 {
22 TerminateProcess(handle, 1);
23 }
24 }
25}
26
27pub fn is_zombie_process(#[allow(unused_variables)] pid: u32) -> bool {
29 #[cfg(unix)]
30 {
31 use std::fs;
32
33 let stat_path = format!("/proc/{}/stat", pid);
34 if let Ok(stat_content) = fs::read_to_string(stat_path) {
35 let fields: Vec<&str> = stat_content.split_whitespace().collect();
36 if fields.len() > 2 {
37 return fields[2] == "Z";
38 }
39 }
40 }
41
42 false
45}