Skip to main content

Process

Struct Process 

Source
pub struct Process { /* private fields */ }
Expand description

A handle on the process holding one pid at the moment it was opened.

Implementations§

Source§

impl Process

Source

pub fn open(pid: u32) -> Result<Option<Self>>

Open a handle on the process now holding pid.

Ok(None) means no process holds that pid (on macOS, also a zombie awaiting its reap; on Linux a zombie opens, and Self::observe then reports it as exited). On Linux this opens a pidfd, which from then on refers to this exact process even if it exits and the pid is reused; when the kernel cannot open one (older than 5.3, or a seccomp policy refusing the call) the handle falls back to the pid, as on macOS.

Source

pub fn pid(&self) -> u32

Source

pub fn signals_through_pidfd(&self) -> bool

True when signals go through a pidfd, so they cannot reach a different process that has since reused this pid.

Source

pub fn observe(&self) -> Option<Observation>

The process’s start time and executable, or None when it has exited (including as a zombie not yet reaped) or cannot be observed. On Linux, Self::is_alive_but_unobservable distinguishes a hidden procfs entry.

Source

pub fn is_alive_but_unobservable(&self) -> bool

Whether Linux hides the entire procfs entry while the process still exists. This proves existence, not identity, and never authorizes a signal. Other platforms return false without changing their observation behavior.

Source

pub fn observe_with_executable_access( &self, ) -> Option<(Observation, ExecutableAccess)>

Observe the process and distinguish Linux executable permission denial from other failures, without changing the legacy observation’s fields. Other platforms retain their existing readable/unavailable distinction.

Source

pub fn signal(&self, signal: Signal) -> Result<bool>

Send signal to the process.

With a pidfd the signal can only reach the process this handle was opened on: if that process has exited, the call fails with ESRCH even if the pid has been reused. Without one (macOS, or a Linux kernel with no pidfd) the signal goes to whatever holds the pid now, so callers should Self::observe immediately before signalling. What remains is the time between that check and this call; for a different process to be hit, the checked one must exit, be reaped, and have its pid handed to a new process inside that window, and both kernels hand out pids in increasing order, so a reuse needs the whole pid space to wrap first.

Ok(false) means the process had already exited (ESRCH).

Trait Implementations§

Source§

impl Debug for Process

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.