rusty_fork

Struct ChildWrapper

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

Wraps a std::process::Child to coordinate state between std and wait_timeout.

This is necessary because the completion of a call to wait_timeout::ChildExt::wait_timeout leaves the Child in an inconsistent state, as it does not know the child has exited, and on Unix may end up referencing another process.

Documentation for this struct’s methods is largely copied from the Rust std docs.

Implementations§

Source§

impl ChildWrapper

Source

pub fn inner(&self) -> &Child

Return a reference to the inner std::process::Child.

Use care on the returned object, as it does not necessarily reference the correct process unless you know the child process has not exited and no wait calls have succeeded.

Source

pub fn inner_mut(&mut self) -> &mut Child

Return a mutable reference to the inner std::process::Child.

Use care on the returned object, as it does not necessarily reference the correct process unless you know the child process has not exited and no wait calls have succeeded.

Source

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

Forces the child to exit. This is equivalent to sending a SIGKILL on unix platforms.

If the process has already been reaped by this handle, returns a NotFound error.

Source

pub fn id(&self) -> u32

Returns the OS-assigned processor identifier associated with this child.

This succeeds even if the child has already been reaped. In this case, the process id may reference no process at all or even an unrelated process.

Source

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

Waits for the child to exit completely, returning the status that it exited with. This function will continue to have the same return value after it has been called at least once.

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.

If the child process has already been reaped, returns its exit status without blocking.

Source

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

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

This function will not block the calling thread and will only advisorily check to see if the child process has exited or not. If the child has exited then on Unix the process id is reaped. This function is guaranteed to repeatedly return a successful exit status so long as the child has already exited.

If the child has exited, then Ok(Some(status)) is returned. If the exit status is not available at this time then Ok(None) is returned. If an error occurs, then that error is returned.

Source

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

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.

By default, stdin, stdout and stderr are inherited from the parent. (In the context of rusty_fork, they are by default redirected to a file.) 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.

If the process has already been reaped, returns a NotFound error.

Source

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

Wait for the child to exit, but only up to the given maximum duration.

If the process has already been reaped, returns its exit status immediately. Otherwise, if the process terminates within the duration, returns Ok(Sone(..)), or Ok(None) otherwise.

This is only present if the “timeout” feature is enabled.

Trait Implementations§

Source§

impl Debug for ChildWrapper

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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V