Skip to main content

UnixProcess

Struct UnixProcess 

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

A spawned Unix process and its supporting tasks.

The exit watcher owns the child, records its exit code in ExitCodeCell, and cancels the provided exit token. Background log pumps forward stdout/stderr lines to a shared sink.

The child leads a new process group so signals reach it and descendants that remain in the group. Call cleanup to give the group time to shut down gracefully before sending SIGKILL. Dropping the value also sends SIGKILL unless cleanup has already sent it.

§Limits

  • Descendants can escape group signals by changing groups (for example with setsid). If they hold stdout or stderr open, cleanup aborts the log pumps after a timeout.
  • Drop does not run if the owning process is killed by SIGKILL or the OOM killer, or calls std::process::exit.
  • The OS may reuse an empty group’s ID before killpg runs, risking a signal to an unrelated group.

Implementations§

Source§

impl UnixProcess

Source

pub async fn spawn( config: UnixProcessConfig, log_sink: Arc<Mutex<dyn LogSink>>, exit_token: CancellationToken, ) -> Result<Self, GenericError>

Spawns the process described by config. The provided log_sink receives each line of captured stdout/stderr; the provided exit_token is cancelled when the process exits.

Source

pub fn name(&self) -> &str

Returns the display name of the process.

Source

pub fn exit_code_cell(&self) -> ExitCodeCell

Returns a clone of the shared ExitCodeCell.

Wait for the exit token passed to spawn before reading.

Source

pub async fn cleanup(self)

Stops the process group and waits for its background tasks.

Sends SIGTERM to the group, allows a grace period for shutdown, then sends SIGKILL. Waits for the exit watcher and log pumps to finish, aborting unfinished tasks after a timeout.

Dropping this future before SIGKILL drops the UnixProcess, which sends SIGKILL instead.

Trait Implementations§

Source§

impl Drop for UnixProcess

Source§

fn drop(&mut self)

Executes the destructor for this type. 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, 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<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