Skip to main content

Child

Struct Child 

Source
pub struct Child {
    pub seccomp_notif: Option<SeccompNotif>,
    pub stdin: Option<ChildStdin>,
    pub stdout: Option<ChildStdout>,
    pub stderr: Option<ChildStderr>,
    /* private fields */
}
Expand description

Represents a child process.

NOTE: The child process is not killed or waited on when Child is dropped. If Child is not waited on before dropped, the child will continue to run in the background and may become a “zombie” after the parent exits. It is therefore best practice to always wait on child processes.

Fields§

§seccomp_notif: Option<SeccompNotif>

A handle to the seccomp notifier, if requested. This must be consumed or dropped for the child to be able to exit.

§stdin: Option<ChildStdin>

The handle for writing to the child’s standard input (stdin), if it has been captured.

§stdout: Option<ChildStdout>

The handle for reading from the child’s standard output (stdout), if it has been captured.

§stderr: Option<ChildStderr>

The handle for reading from the child’s standard error (stderr), if it has been captured.

Implementations§

Source§

impl Child

Source

pub fn id(&self) -> Pid

Returns the PID of the child.

Source

pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>

Attempts to collect the exit status of the child if it has already exited.

Source

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

Waits for the child to exit completely, returning its exit status. This function will continue to return the same exit status after the child process has fully exited.

To avoid deadlocks, the child’s stdin handle, if any, will be closed before waiting. Otherwise, the child could block waiting for input from the parent while the parent is waiting for the child. To keep the stdin handle open and control it explicitly, the caller can .take() it before calling .wait().

Source

pub fn wait_blocking(&mut self) -> Result<ExitStatus>

Blocks until the child process exits.

Source

pub async fn wait_with_output(self) -> Result<Output>

Simultaneously waits for the child to exit and collect all remaining output on the stdout/stderr handles, returning an Output instance.

To avoid deadlocks, the child’s stdin handle, if any, will be closed before waiting. Otherwise, the child could block waiting for input from the parent while the parent is waiting for the child.

By default, stdin, stdout and stderr are inherited from the parent. In order to capture the output into this Result<Output> it is necessary to create new pipes between parent and child. Use stdout(Stdio::piped()) or stderr(Stdio::piped()), respectively.

Source

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

Sends a signal to the child. If the child has already been waited on, this does nothing and returns success.

Trait Implementations§

Source§

impl Debug for Child

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Child

§

impl !UnwindSafe for Child

§

impl Freeze for Child

§

impl Send for Child

§

impl Sync for Child

§

impl Unpin for Child

§

impl UnsafeUnpin for Child

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.