Skip to main content

Process

Struct Process 

Source
pub struct Process(/* private fields */);
Expand description

A handle to a running or finished subprocess.

Process is a lightweight handle that tracks a child process’s lifecycle. It is created internally by Exec::start and Pipeline::start and appears as part of the Job struct.

Unlike std::process::Child, all methods on Process take &self rather than &mut self, so a Process can be shared between threads without external synchronization.

Process is cheaply cloneable. Clones share the same underlying process handle, so e.g. calling wait() on one clone will also make the exit status available to all other clones.

§Drop behavior

When the last clone of a Process is dropped, it waits for the child process to finish unless detach has been called. Because Process does not own any pipes to the child, callers must ensure that any pipes connected to the child’s stdin are dropped before the Process is dropped. Otherwise, the child may block waiting for input while the Process drop waits for the child to exit, resulting in a deadlock. Job handles this automatically via field declaration order.

Implementations§

Source§

impl Process

Source

pub fn pid(&self) -> u32

Returns the PID of the subprocess.

Source

pub fn exit_status(&self) -> Option<ExitStatus>

Returns the exit status, if the process is known to have finished.

This does not perform any system calls. To check whether the process has finished, use poll or wait.

Source

pub fn poll(&self) -> Option<ExitStatus>

Check whether the process has finished, without blocking.

Returns Some(exit_status) if the process has finished, None if it is still running.

Source

pub fn wait(&self) -> Result<ExitStatus>

Wait for the process to finish and return its exit status.

If the process has already finished, returns the cached exit status immediately.

Source

pub fn wait_timeout(&self, dur: Duration) -> Result<Option<ExitStatus>>

Wait for the process to finish, timing out after the specified duration.

Returns Ok(None) if the timeout elapsed before the process finished.

Source

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

Terminate the subprocess.

On Unix, this sends SIGTERM. On Windows, this calls TerminateProcess.

If the process has already been reaped, this is a no-op to avoid signaling a potentially reused PID.

Source

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

Kill the subprocess.

On Unix, this sends SIGKILL. On Windows, this calls TerminateProcess.

If the process has already been reaped, this is a no-op to avoid signaling a potentially reused PID.

Source

pub fn detach(&self)

Mark the process as detached.

A detached process will not be waited on when the Process is dropped.

Trait Implementations§

Source§

impl Clone for Process

Source§

fn clone(&self) -> Process

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Process

Source§

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

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

impl ProcessExt for Process

Source§

fn send_signal(&self, signal: i32) -> Result<()>

Send the specified signal to the child process. Read more
Source§

fn send_signal_group(&self, signal: i32) -> Result<()>

Send the specified signal to the child’s process group. 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> 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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.