pub fn process_start_time(pid: u32) -> Option<i64>Expand description
pid’s process start time as Unix epoch seconds (rounded to the nearest
second — see ProcessIdentity::check’s tolerance for why sub-second
precision isn’t needed), or None if it can’t be determined (process
gone by the time we looked, ps unavailable, or a read/parse failure —
all treated the same by callers: “couldn’t verify, can’t use this for
the reuse check”).
Deliberately shells out to ps -o etime= rather than hand-rolling the
sysctl(KERN_PROC_PID)/kinfo_proc FFI: libc doesn’t expose
kinfo_proc’s layout for macOS (only for the free/net/openbsd targets),
so getting that struct’s field offsets right would mean hand-maintaining
an unsafe #[repr(C)] mirror of an Apple-internal struct with no
compiler to check it against — a correctness risk ps’s stable,
documented output doesn’t carry.
etime (not GNU/Linux procps’s etimes extension, which macOS’s ps
rejects outright — ps: etimes: keyword not found) prints elapsed time
as [[dd-]hh:]mm:ss, a purely numeric, locale- and timezone-independent
format supported by both, so one parser (parse_elapsed) covers both
rather than two platform-specific implementations.
Unix-only: there’s no ps -o etime= equivalent on other platforms.
Gated with cfg rather than left to fail at runtime so a non-Unix build
never shells out to a command that can’t exist there — see the
cfg(not(unix)) arm just below.