Skip to main content

ProcessHandle

Trait ProcessHandle 

Source
pub trait ProcessHandle: Send {
    // Required methods
    fn pid(&self) -> Option<u32>;
    fn process_group_id(&self) -> Option<u32>;
    fn killer(&self) -> Arc<dyn ProcessKiller> ;
    fn take_stdin(&mut self) -> Option<Box<dyn Write + Send>>;
    fn take_stdout(&mut self) -> Option<Box<dyn Read + Send>>;
    fn take_stderr(&mut self) -> Option<Box<dyn Read + Send>>;
    fn wait_with_timeout(
        &mut self,
        timeout: Option<Duration>,
    ) -> Result<(Option<ExitStatus>, bool)>;
    fn wait(&mut self) -> Result<ExitStatus>;
}
Expand description

Handle to a running (or finished) process. Used by both the synchronous proc::run path and the long-running waiter thread.

The trait is intentionally small: the legacy code already managed stdout/stderr drain on dedicated threads, and stdin is written once after spawn — wrapping those reads/writes via boxed trait objects keeps the real and mock paths uniform without forcing async into the rest of the hostlib.

Required Methods§

Source

fn pid(&self) -> Option<u32>

OS process id, when available.

Source

fn process_group_id(&self) -> Option<u32>

OS process group id, when available. Falls back to Self::pid on platforms that don’t expose process groups.

Source

fn killer(&self) -> Arc<dyn ProcessKiller>

Returns a killer that can terminate the process even after the stdout/stderr/wait halves have been moved into the waiter thread.

Source

fn take_stdin(&mut self) -> Option<Box<dyn Write + Send>>

Take ownership of the stdin pipe, if the spawn requested one.

Source

fn take_stdout(&mut self) -> Option<Box<dyn Read + Send>>

Take ownership of the stdout reader.

Source

fn take_stderr(&mut self) -> Option<Box<dyn Read + Send>>

Take ownership of the stderr reader.

Source

fn wait_with_timeout( &mut self, timeout: Option<Duration>, ) -> Result<(Option<ExitStatus>, bool)>

Wait for the process to exit, optionally with a timeout. Returns (Some(status), false) when the process exited cleanly, (None, true) when the timeout elapsed (and the spawner killed the child), or (None, false) when the wait failed for a reason other than the timeout.

Source

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

Block until the process exits, no timeout.

Implementors§