pub struct ProcessIdentity {
pub pid: u32,
pub started_at: i64,
}Expand description
A process, identified precisely enough to answer “is this still the same process I saw before, or did its pid get recycled?” — a bare pid can’t answer that on its own.
Why this matters: pid-only liveness (kill(pid, 0) == 0) has a
latent failure mode on long-running systems — if the holder crashes and
some unrelated new process happens to be assigned the same pid before
the next check, pid-only liveness reports “still alive” and the lock is
refused forever (until someone manually deletes the lock file). Not a
theoretical risk: pid space wraps around on any system that’s been
running long enough. Comparing the recorded start time against the
current holder of that pid closes the gap — a reused pid almost never
has the exact same start time as whatever held it before.
Fields§
§pid: u32§started_at: i64Implementations§
Source§impl ProcessIdentity
impl ProcessIdentity
pub fn current() -> Self
Sourcepub fn check(recorded: &ProcessIdentity) -> ProcessLiveness
pub fn check(recorded: &ProcessIdentity) -> ProcessLiveness
Four-way liveness/reuse check against a recorded identity (e.g. one read back from a lock file):
Alive—pidis running and its start time still matches (within [START_TIME_TOLERANCE_SECS]); the recorded holder is genuinely still there.Reused—pidis running but its start time no longer matches the recorded one — a different process now holds this pid.Dead—pidisn’t running at all.Unknown— liveness or start time couldn’t be determined at all (unsupported platform,psunavailable, or the recorded value itself was never captured —started_at == 0). Distinct fromReusedon purpose: “can’t tell” and “confirmed a different process” call for different caller behavior (seedecide_stale_lock) — collapsing them would mean an unverifiable lock gets silently reclaimed out from under a holder that may well still be alive.