diff --git a/Cargo.toml b/Cargo.toml index 437a15c..d8c7807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ license = "MIT" [dependencies] clap = { version = "4.5", features = ["derive"] } -sysinfo = "0.29.11" -tabled = "0.14.0" -serde = { version = "1.0.193", features = ["derive"] } -dirs = "5.0.1" -serde_json = "1.0.108" -crossterm = "0.28.1" -once_cell = "1.18.0" -ctrlc = "3.4.5" -windows-sys = "0.36.1" +sysinfo = "0.33" +tabled = "0.17" +serde = { version = "1.0", features = ["derive"] } +dirs = "6.0.0" +serde_json = "1.0" +crossterm = "0.28" +once_cell = "1.18" +ctrlc = "3.4" +windows-sys = "0.59" diff --git a/src/commands/list.rs b/src/commands/list.rs index 018ea92..705c63b 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,6 +1,6 @@ use crate::config::dump::DumpConfig; use serde::{Deserialize, Serialize}; -use sysinfo::{ProcessExt, System, SystemExt, UserExt}; +use sysinfo::System; use tabled::{Table, Tabled}; #[derive(Serialize, Deserialize)] @@ -83,8 +83,7 @@ pub fn read_pmr_processes() -> Vec { } pub fn list_processes(system: bool) { - let mut sys = System::new(); - sys.refresh_all(); + let sys = System::new_all(); if system { let processes: Vec = sys @@ -92,7 +91,7 @@ pub fn list_processes(system: bool) { .iter() .map(|(&pid, process)| ProcessInfo { id: "0".to_string(), - name: process.name().to_string(), + name: process.name().to_str().unwrap_or("unknown").to_string(), namespace: "default".to_string(), version: "N/A".to_string(), pid: pid.to_string(), @@ -101,10 +100,7 @@ pub fn list_processes(system: bool) { status: process.status().to_string(), cpu: format!("{:.1}%", process.cpu_usage()), mem: format!("{:.1} MB", process.memory() as f64 / 1024.0 / 1024.0), - user: process - .user_id() - .and_then(|uid| sys.get_user_by_id(uid)) - .map_or("N/A".to_string(), |u| u.name().to_string()), + user: "N/A".to_string(), }) .collect(); @@ -130,10 +126,7 @@ pub fn list_processes(system: bool) { status: "running".to_string(), cpu: format!("{:.1}%", sys_proc.cpu_usage()), mem: format!("{:.1} MB", sys_proc.memory() as f64 / 1024.0 / 1024.0), - user: sys_proc - .user_id() - .and_then(|uid| sys.get_user_by_id(uid)) - .map_or("N/A".to_string(), |u| u.name().to_string()), + user: "N/A".to_string(), } } else { // 进程不存在,但PID > 0,说明进程已经退出