Skip to main content

Process

Struct Process 

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

A handle to a process this VFS did not spawn.

Holding one is what makes the operations below refer to a single process rather than to whatever currently owns a PID. How strong that guarantee is varies:

  • Linux (pidfd) and Windows (a process handle pins the PID against reuse) are race-free for the whole life of the handle.
  • FreeBSD and macOS validate identity at open and cannot maintain it: kill(2) takes a PID, and Capsicum mints process descriptors only through pdfork, so there is no handle to hold for a process this one did not fork. Process::signal and Process::terminate are racy there.

Implementations§

Source§

impl Process

Source

pub fn pid(&self) -> u32

Returns the process ID.

The only attribute projected directly: it is fixed for the life of the handle, where everything else has to be re-read to be true.

Source

pub async fn info(&self) -> Result<ProcessInfo>

Takes a fresh snapshot of the process.

Source

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

Sends a signal to the process.

Fails with ErrorKind::Unsupported on a Windows target. The method exists there regardless, because the target may be remote: whether signals exist is a property of the target, not of the host this code was compiled for.

Source

pub async fn terminate(&self) -> Result<()>

Asks the process to terminate.

SIGTERM on Unix, TerminateProcess on Windows. Unconditional, with no grace period and no escalation, unlike Child::terminate: the graceful half of that path relies on children being spawned into a process group of their own, which is not something that can be arranged after the fact. Compose terminate, wait, a timeout, and kill for grace with escalation.

Note the asymmetry this leaves on Windows, where TerminateProcess is not a request the target can decline or clean up after.

Source

pub async fn kill(&self) -> Result<()>

Kills the process.

SIGKILL on Unix, TerminateProcess on Windows — the strongest stop the target offers, and one the process cannot catch or clean up after.

On a Windows target this is terminate under another name, since TerminateProcess is already unconditional and there is nothing harder to escalate to. The pair exists because on Unix the distinction is real, and a portable caller should be able to ask for either without branching on the target.

Source

pub async fn wait(&self) -> Result<ProcessExit>

Waits for the process to exit.

Source

pub async fn close(self) -> Result<()>

Closes the handle.

Not required: a dropped Process closes itself, and a remote one is released when the session’s object table is torn down. This exists so a caller can observe a close failure instead of discarding it.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.