GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.03k stars 302 forks source link

Add some way to remove a closed process #1340

Open CryZe opened 1 month ago

CryZe commented 1 month ago

I'm attaching to specific individual processes and want to know when they are closed, so I use

if system.refresh_processes_specifics(ProcessesToUpdate::Some(&[pid]), ProcessRefreshKind::new()) == 0 {
    ...
}

to check for that situation. Unfortunately as stated by the documentation, this does not remove it from the entire list of processes. This means I need to run

system.refresh_processes_specifics(
    ProcessesToUpdate::All,
    ProcessRefreshKind::new().with_exe(UpdateKind::OnlyIfNotSet),
);

inside to ensure it gets removed. This is very wasteful. I'd appreciate some sort of way for me to either manually remove it from the list or some argument I can pass / config I can set, so it gets removed properly.

Though arguably the entire default seems questionable to me too.

GuillaumeGomez commented 1 month ago

Interesting: I was thinking about adding a new remove_dead_processes boolean field in ProcessProcessKind or as new parameter. Not clear yet. I suppose it would fix your case?

CryZe commented 1 month ago

Yeah absolutely, as long as it doesn't wastefully have to scan the entire process list or so.

GuillaumeGomez commented 1 month ago

Sadly it kinda still needs to iterate processes or PIDs depending on the platform.

CryZe commented 1 month ago

Can it not reuse the information it got from just refreshing the single process?

GuillaumeGomez commented 1 month ago

Just refreshing one process, depending on the platform, can require to go through processes/PIDs list given by the system.

CryZe commented 1 month ago

I guess that's fine, as long as it can directly use that information and not query it a second time, like I do currently.