Skip to main content

ProcessIdentity

Struct ProcessIdentity 

Source
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: i64

Implementations§

Source§

impl ProcessIdentity

Source

pub fn current() -> Self

Source

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 — pid is running and its start time still matches (within [START_TIME_TOLERANCE_SECS]); the recorded holder is genuinely still there.
  • Reused — pid is running but its start time no longer matches the recorded one — a different process now holds this pid.
  • Dead — pid isn’t running at all.
  • Unknown — liveness or start time couldn’t be determined at all (unsupported platform, ps unavailable, or the recorded value itself was never captured — started_at == 0). Distinct from Reused on purpose: “can’t tell” and “confirmed a different process” call for different caller behavior (see decide_stale_lock) — collapsing them would mean an unverifiable lock gets silently reclaimed out from under a holder that may well still be alive.

Trait Implementations§

Source§

impl Clone for ProcessIdentity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ProcessIdentity

Source§

impl Debug for ProcessIdentity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ProcessIdentity

Source§

impl PartialEq for ProcessIdentity

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ProcessIdentity

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more