Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old process data is displayed, and refresh doesn't work #1459

Open
charl1e7 opened this issue Jan 23, 2025 · 0 comments
Open

Old process data is displayed, and refresh doesn't work #1459

charl1e7 opened this issue Jan 23, 2025 · 0 comments
Labels

Comments

@charl1e7
Copy link

I'm unable to properly track the status of a program. If the program exits, its last data remains displayed, and calling refresh does not work. Only reinitializing the System instance resolves the issue(Well, almost).

Here's an example code snippet to demonstrate the issue:

// [dependencies]
// sysinfo = "0.33.1"
use sysinfo::{Pid, System};
use std::env;
use std::thread;
use std::time::Duration;

fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        println!("Usage: {} <pid>", args[0]);
        return;
    }

    let pid = match args[1].parse::<u32>() {
        Ok(pid) => pid as usize,
        Err(_) => {
            println!("Invalid PID format");
            return;
        }
    };

    let mut system_refresh = System::new();
    println!("Starting process monitoring...\n");
    
    loop {
        print!("Refresh method: ");
        system_refresh.refresh_all();
        match system_refresh.process(Pid::from(pid)) {
            Some(process) => println!("Status: {:?}", process.status()),
            None => println!("Status: Not Found"),
        }

        print!("New instance: ");
        let mut system_new = System::new();
        system_new.refresh_all();
        match system_new.process(Pid::from(pid)) {
            Some(process) => println!("Status: {:?}", process.status()),
            None => println!("Status: Not Found"),
        }

        println!("----------------------------------------");
        thread::sleep(Duration::from_secs(2));
    }
}

Image
And as can be seen in the image, the new initialization correctly detects that the process is no longer running(not found), while refresh still considers the program to be Run.
I would like the process status to be tracked correctly.And I think my question aligns with this.

@charl1e7 charl1e7 added the bug label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant