pub struct ProcessIdentity { /* private fields */ }Expand description
A PID paired with a token that changes when the process at that PID does.
Serializable because its whole reason to exist is being written to the attempt journal and read back after a restart. The token is opaque: its shape is documented at the module level for diagnostics, but nothing should parse it. Comparison — not interpretation — is the operation it supports.
Implementations§
Source§impl ProcessIdentity
impl ProcessIdentity
Sourcepub fn resolve(pid: u32) -> Result<Self, ProcessError>
pub fn resolve(pid: u32) -> Result<Self, ProcessError>
Reads the identity of a live process.
§Errors
ProcessError::NoSuchProcess when nothing holds the PID, and
ProcessError::Identity when the operating system refuses to answer —
a process owned by another account, for instance. The two are separate
because “gone” is a normal lifecycle answer and “refused” is a
misconfiguration.
Sourcepub fn of_current_process() -> Result<Self, ProcessError>
pub fn of_current_process() -> Result<Self, ProcessError>
The identity of the calling process.
§Errors
As ProcessIdentity::resolve, though a process can always see itself
in practice.
Sourcepub const fn pid(&self) -> u32
pub const fn pid(&self) -> u32
The PID. Recorded in RunnerAttempt::process_id and shown in the UI;
never used on its own to decide whether a process is ours.
Sourcepub fn start_token(&self) -> &str
pub fn start_token(&self) -> &str
The opaque start token. Exposed for diagnostics only.
Sourcepub fn recheck(&self) -> Result<Adoption, ProcessError>
pub fn recheck(&self) -> Result<Adoption, ProcessError>
Re-resolves this identity against the machine as it is now.
§Errors
ProcessError::Identity when the operating system refuses to answer.
A PID that resolves to nothing is Adoption::Gone, not an error.
Sourcepub fn terminate(&self, grace: Duration) -> Result<Termination, ProcessError>
pub fn terminate(&self, grace: Duration) -> Result<Termination, ProcessError>
Stops the process this identity names, and nothing else.
Re-checks the identity immediately before signalling. That check is the
difference between “terminate the runner recorded in the journal” and
“terminate whatever now holds PID 4312”, and it is why the recycled case
returns Termination::RefusedPidRecycled rather than proceeding.
grace applies only where the platform has a polite stop to offer: on
Unix the process is sent SIGTERM, given grace to exit, and then
SIGKILLed. Windows has no console-independent equivalent, so the
process is terminated immediately and grace is ignored — stated here
rather than emulated, because a fake grace period that never actually
asks politely is worse than no grace period.
§Errors
ProcessError::Control when signalling fails for a reason other than
the process having already exited.
Trait Implementations§
Source§impl Clone for ProcessIdentity
impl Clone for ProcessIdentity
Source§fn clone(&self) -> ProcessIdentity
fn clone(&self) -> ProcessIdentity
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more