Skip to main content

Process

Struct Process 

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

A process Launcher::spawn started, the leader of a process group of its own. Dropping it while it runs kills the group and reaps it.

Implementations§

Source§

impl Process

Source

pub fn id(&self) -> u32

The process’s id, which is also its group’s.

Source

pub fn through(self, host: impl Into<String>) -> Self

The same process, marked as the local end of a transport that runs the command on the machine host: stopping it stops the transport, and what that does there is the transport’s to say.

Source

pub fn remote(&self) -> Option<&str>

The machine it runs the command on through a transport, if it was marked so (through).

Source

pub fn forced(&self) -> bool

Whether the last stop had to kill it: it was still running its grace period after SIGTERM.

Source

pub fn lines(&self) -> &Receiver<OutputLine>

Its output, line by line, as it comes. Lines wait here until they are received; the channel disconnects once every process holding the output closed it.

Source

pub fn group(&self) -> Group

A handle that stops its group from another thread, such as the one dropping the call that waits for it.

Source

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

How it ended, if it has.

Source

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

Waits at most timeout for it to end, and says how it ended if it did. Its output keeps arriving at lines meanwhile. A timeout too long for the clock, such as Duration::MAX, waits until it ends.

Source

pub fn output(self, timeout: Option<Duration>) -> Result<Output>

Runs it to its end, at most timeout (None waits as long as it takes), and returns what it printed on stdout and on stderr (with Spawn::merge_stderr, all of it on stdout) and how it ended. A blocking call: run it on a thread of its own, such as inside blocking. Past timeout the error is io::ErrorKind::TimedOut; otherwise as run.

use rig_tools::process::{Launcher, Spawn};

let process = Launcher::default().spawn("sh", ["-c", "echo hi"], Spawn::default())?;
let output = process.output(Some(std::time::Duration::from_secs(5)))?;
assert_eq!(output.stdout, b"hi\n");
assert!(output.status.success());
Source

pub fn run( &mut self, deadline: Option<Instant>, quiet: Option<Duration>, sink: impl FnMut(OutputLine) -> bool, ) -> Result<Ended>

Waits for it to end, at most until deadline (None waits as long as it takes) and, with quiet, while it printed something within that long, handing each piece of its output to sink; sink returning false stops the wait. A blocking call.

After an exit, something it left running that still holds its output gets a moment (100 ms) to finish, then the rest of its group is killed; past the deadline or stopped, the group is stopped with STOP_GRACE. After a kill, reading goes on for that moment: a process that left the group survives the kill and may hold the pipe for good.

Source

pub fn stop(&mut self, grace: Duration) -> Result<ExitStatus>

Asks its group to stop (SIGTERM), waits at most grace for it to end, then kills the group. Elsewhere than unix it is killed at once.

Source

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

Kills its group (SIGKILL), also what is left of it after the process itself ended, and says how the process ended. Kill within moments of the end: once the group is empty its id is free again.

Trait Implementations§

Source§

impl Drop for Process

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more