Skip to main content

polars_utils/
sys.rs

1pub use polars_config::total_memory;
2
3/// Check whether a process with the given PID is currently alive.
4///
5/// Used by `polars_ooc::cleaner::cleanup_stale_dirs` to remove spill
6/// directories left behind by dead processes on startup.
7pub fn is_process_alive(pid: u32) -> bool {
8    use sysinfo::{Pid, ProcessRefreshKind, System, UpdateKind};
9    let pid = Pid::from_u32(pid);
10    let mut sys = System::new();
11    sys.refresh_processes_specifics(
12        sysinfo::ProcessesToUpdate::Some(&[pid]),
13        true,
14        ProcessRefreshKind::nothing().with_cmd(UpdateKind::Never),
15    );
16    sys.process(pid).is_some()
17}