1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use anyhow::anyhow;
use clap::ArgMatches;
use notify_rust::Timeout;
use sysinfo::{Pid, ProcessExt, ProcessRefreshKind, RefreshKind, System, SystemExt};

pub fn main(matches: &ArgMatches) -> anyhow::Result<()> {
    let pid = *matches.get_one::<u32>("pid").unwrap();

    let system = System::new_with_specifics(
        RefreshKind::default().with_processes(ProcessRefreshKind::default()),
    );

    let Some(process) = system.process(Pid::from(pid as usize)) else {
        return Err(anyhow!("Process with pid {} doesn't exist", pid));
    };

    process.wait();
    notify_rust::Notification::new()
        .summary(&format!("Process with pid {} exited", pid))
        .timeout(Timeout::Never)
        .show()?;
    Ok(())
}