Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

procinfo: add per-pid argv readers

RoversXbb7ef1d595cf
diff --git a/procinfo/src/lib.rs b/procinfo/src/lib.rs
index 08f04236..bfebcb7b 100644
--- a/procinfo/src/lib.rs
+++ b/procinfo/src/lib.rs
@@ -96,4 +96,9 @@ impl LocalProcessInfo {
pub fn executable_path(_pid: u32) -> Option<PathBuf> {
None
}
+
+ #[cfg(not(any(target_os = "macos", target_os = "linux", windows)))]
+ pub fn argv_for_pid(_pid: u32) -> Option<Vec<String>> {
+ None
+ }
}
diff --git a/procinfo/src/linux.rs b/procinfo/src/linux.rs
index 5170a2c0..b5799d8e 100644
--- a/procinfo/src/linux.rs
+++ b/procinfo/src/linux.rs
@@ -28,6 +28,22 @@ impl LocalProcessInfo {
std::fs::read_link(format!("/proc/{}/exe", pid)).ok()
}
+ /// The argument vector of one process: a single `/proc` file read,
+ /// unlike `with_root_pid` which scans the whole process table. `None`
+ /// when the process is gone or exposes no cmdline (kernel threads).
+ pub fn argv_for_pid(pid: u32) -> Option<Vec<String>> {
+ let data = std::fs::read(format!("/proc/{}/cmdline", pid)).ok()?;
+ let data = data.strip_suffix(&[0]).unwrap_or(&data);
+ if data.is_empty() {
+ return None;
+ }
+ Some(
+ data.split(|&c| c == 0)
+ .map(|arg| String::from_utf8_lossy(arg).to_string())
+ .collect(),
+ )
+ }
+
pub fn with_root_pid(pid: u32) -> Option<Self> {
use libc::pid_t;
diff --git a/procinfo/src/macos.rs b/procinfo/src/macos.rs
index 4c2aeeda..dd167d7c 100644
--- a/procinfo/src/macos.rs
+++ b/procinfo/src/macos.rs
@@ -129,34 +129,6 @@ impl LocalProcessInfo {
LocalProcessInfo::current_working_dir(pid as _).unwrap_or_else(PathBuf::new)
}
- fn exe_and_args_for_pid_sysctl(pid: libc::pid_t) -> Option<(PathBuf, Vec<String>)> {
- use libc::c_int;
- let mut size = 64 * 1024;
- let mut buf: Vec<u8> = Vec::with_capacity(size);
- let mut mib = [libc::CTL_KERN, libc::KERN_PROCARGS2, pid as c_int];
-
- let res = unsafe {
- libc::sysctl(
- mib.as_mut_ptr(),
- mib.len() as _,
- buf.as_mut_ptr() as *mut _,
- &mut size,
- std::ptr::null_mut(),
- 0,
- )
- };
- if res == -1 {
- return None;
- }
- if size < (std::mem::size_of::<c_int>() * 2) {
- // Not big enough
- return None;
- }
- unsafe { buf.set_len(size) };
-
- parse_exe_and_argv_sysctl(buf)
- }
-
fn exe_for_pid(pid: libc::pid_t) -> PathBuf {
LocalProcessInfo::executable_path(pid as _).unwrap_or_else(PathBuf::new)
}
@@ -197,6 +169,42 @@ impl LocalProcessInfo {
None
}
}
+
+ /// The argument vector of one process: a single sysctl, unlike
+ /// `with_root_pid` which enumerates the whole process table.
+ /// `KERN_PROCARGS2` reflects runtime argv rewrites, which is what
+ /// wrapper unwrapping wants to see.
+ pub fn argv_for_pid(pid: u32) -> Option<Vec<String>> {
+ exe_and_args_for_pid_sysctl(pid as libc::pid_t).map(|(_, argv)| argv)
+ }
+}
+
+fn exe_and_args_for_pid_sysctl(pid: libc::pid_t) -> Option<(PathBuf, Vec<String>)> {
+ use libc::c_int;
+ let mut size = 64 * 1024;
+ let mut buf: Vec<u8> = Vec::with_capacity(size);
+ let mut mib = [libc::CTL_KERN, libc::KERN_PROCARGS2, pid as c_int];
+
+ let res = unsafe {
+ libc::sysctl(
+ mib.as_mut_ptr(),
+ mib.len() as _,
+ buf.as_mut_ptr() as *mut _,
+ &mut size,
+ std::ptr::null_mut(),
+ 0,
+ )
+ };
+ if res == -1 {
+ return None;
+ }
+ if size < (std::mem::size_of::<c_int>() * 2) {
+ // Not big enough
+ return None;
+ }
+ unsafe { buf.set_len(size) };
+
+ parse_exe_and_argv_sysctl(buf)
}
fn parse_exe_and_argv_sysctl(buf: Vec<u8>) -> Option<(PathBuf, Vec<String>)> {
diff --git a/procinfo/src/windows.rs b/procinfo/src/windows.rs
index bebcd015..f82caf50 100644
--- a/procinfo/src/windows.rs
+++ b/procinfo/src/windows.rs
@@ -356,6 +356,17 @@ impl LocalProcessInfo {
proc.executable()
}
+ /// The argument vector of one process, read from its PEB. `None` when
+ /// the process is gone or its parameters are unreadable.
+ pub fn argv_for_pid(pid: u32) -> Option<Vec<String>> {
+ log::trace!("argv_for_pid({})", pid);
+ let params = ProcHandle::new(pid)?.get_params()?;
+ if params.argv.is_empty() {
+ return None;
+ }
+ Some(params.argv)
+ }
+
pub fn with_root_pid(pid: u32) -> Option<Self> {
log::trace!("LocalProcessInfo::with_root_pid({}), getting snapshot", pid);
let procs = Snapshot::entries();