pub fn process_info(pid: u32) -> Result<Option<MemberInfo>>process-control only.Expand description
Look up the identity and best-effort metadata of an arbitrary process by
pid — the standalone companion to
ProcessGroup::members_info, for a pid the
caller holds outside any group (a pid saved to disk across runs, a launch
registry, an e2e probe watching a process from outside its container).
Returns the very fields a group member’s MemberInfo carries — parent pid,
image name, and the start-time identity token — read through the same
per-platform readers (/proc/<pid>/stat on Linux, proc_pidinfo on macOS,
Toolhelp32 + the creation FILETIME on Windows), with the same honest
Option policy: a field the platform can’t report is None, never fabricated.
§The three outcomes
Ok(Some(info))— the process exists; inspect it viaMemberInfo::ppid,exe_name, andstart_time(eachNonewhere unavailable).Ok(None)— the pid names no process. An honest negative, not an error: this is the “it’s gone” answer a liveness check wants.Err— the process may well exist, but its state couldn’t be determined: the caller lacks permission to inspect it, or the OS read failed. Never read this as “dead” — that is the whole reason it is an error rather thanOk(None).
§No command line
The raw argv / environment is deliberately never read, on any platform — a
command line routinely carries secrets, and redaction is the consumer’s policy
to own (the crate’s standing “never argv/env” stance, the same one
MemberInfo documents).
§Point-in-time
A snapshot taken now: the process may exit immediately afterwards, and the pid
is only as stable as the OS’s reuse policy. To tell a recycled number apart
from the original process later, pair the returned
start_time with the pid and use
process_is_alive — do not trust the bare number.
§Platform notes
- Linux / Android — one
/proc/<pid>/statread; world-readable for other users’ processes on a default mount, so a foreign process is reported. Ahidepidmount that denies the read surfaces asErr, not a false “gone”. - Windows —
OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION)is the existence/permission oracle (the least-privilege query right, grantable across sessions and integrity levels for ordinary processes); ppid and image name come from one system-wideToolhelp32snapshot. A protected / higher-integrity process (an anti-malware PPL, theSystemprocess) the caller may not query yieldsErr(access denied), distinct from a non-existent pid’sOk(None). - macOS — one
proc_pidinfo(PROC_PIDTBSDINFO)fill; a process the caller may not inspect yieldsErr, a gone pidOk(None). - the bare BSDs — no per-process reader is wired up, so existence is probed
with a zero-signal
kill(pid, 0)and the pid is reported with every enriching fieldNone(Ok(Some(_))). That is a correct best-effort result, not an error, and never a false “gone”.
§Errors
ErrorReason::Io when the process may exist but couldn’t be inspected — a
permission denial (a Windows protected process, a Linux hidepid mount, a macOS
restricted process) or another OS read failure.
§Examples
let pid = 4321;
match processkit::process_info(pid)? {
Some(info) => println!(
"pid={} ppid={:?} exe={:?} start={:?}",
info.pid(),
info.ppid(),
info.exe_name(),
info.start_time(),
),
None => println!("pid {pid} is not running"),
}