From 17f38e37ce85c4c5cceb92c6a4f267d5e300ff80 Mon Sep 17 00:00:00 2001 From: KrushnXGIT <256734098+KrushnXGIT@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:26:27 +0530 Subject: [PATCH] pwdx: read only the requested processes To find the working directory of a few processes, pwdx loaded every process on the system with all its details through System::new_all(). Refresh just each requested process, and only its working directory. --- src/uu/pwdx/src/pwdx.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/uu/pwdx/src/pwdx.rs b/src/uu/pwdx/src/pwdx.rs index 376b6783..0e80e032 100644 --- a/src/uu/pwdx/src/pwdx.rs +++ b/src/uu/pwdx/src/pwdx.rs @@ -5,7 +5,7 @@ use clap::{crate_version, Arg, Command}; use std::env; -use sysinfo::{Pid, System}; +use sysinfo::{Pid, ProcessRefreshKind, ProcessesToUpdate, System, UpdateKind}; use uucore::error::{set_exit_code, UResult, USimpleError}; #[uucore::main] @@ -13,7 +13,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; let pids = matches.get_many::("pid").unwrap(); - let sys = System::new_all(); + let mut sys = System::new(); for pid_str in pids { // A pid can also be given as /proc/PID, like in procps-ng. @@ -26,10 +26,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { format!("invalid process id: {pid_str}"), )) } - Ok(pid) => pid, + Ok(pid) => Pid::from(pid), }; - match sys.process(Pid::from(pid)) { + // Read only this process, and only its working directory. + sys.refresh_processes_specifics( + ProcessesToUpdate::Some(&[pid]), + true, + ProcessRefreshKind::nothing().with_cwd(UpdateKind::Always), + ); + match sys.process(pid) { Some(process) => match process.cwd() { Some(cwd) => println!("{pid_str}: {}", cwd.display()), None => {