Enum expectrl::WaitStatus

source ·
pub enum WaitStatus {
    Exited(Pid, i32),
    Signaled(Pid, Signal, bool),
    Stopped(Pid, Signal),
    Continued(Pid),
    StillAlive,
}
Expand description

Possible return values from wait() or waitpid().

Each status (other than StillAlive) describes a state transition in a child process Pid, such as the process exiting or stopping, plus additional data about the transition if any.

Note that there are two Linux-specific enum variants, PtraceEvent and PtraceSyscall. Portable code should avoid exhaustively matching on WaitStatus.

Variants§

§

Exited(Pid, i32)

The process exited normally (as with exit() or returning from main) with the given exit code. This case matches the C macro WIFEXITED(status); the second field is WEXITSTATUS(status).

§

Signaled(Pid, Signal, bool)

The process was killed by the given signal. The third field indicates whether the signal generated a core dump. This case matches the C macro WIFSIGNALED(status); the last two fields correspond to WTERMSIG(status) and WCOREDUMP(status).

§

Stopped(Pid, Signal)

The process is alive, but was stopped by the given signal. This is only reported if WaitPidFlag::WUNTRACED was passed. This case matches the C macro WIFSTOPPED(status); the second field is WSTOPSIG(status).

§

Continued(Pid)

The process was previously stopped but has resumed execution after receiving a SIGCONT signal. This is only reported if WaitPidFlag::WCONTINUED was passed. This case matches the C macro WIFCONTINUED(status).

§

StillAlive

There are currently no state changes to report in any awaited child process. This is only returned if WaitPidFlag::WNOHANG was used (otherwise wait() or waitpid() would block until there was something to report).

Implementations§

source§

impl WaitStatus

source

pub fn pid(&self) -> Option<Pid>

Extracts the PID from the WaitStatus unless it equals StillAlive.

source§

impl WaitStatus

source

pub fn from_raw(pid: Pid, status: i32) -> Result<WaitStatus, Errno>

Convert a raw wstatus as returned by waitpid/wait into a WaitStatus

Errors

Returns an Error corresponding to EINVAL for invalid status values.

Examples

Convert a wstatus obtained from libc::waitpid into a WaitStatus:

use nix::sys::wait::WaitStatus;
use nix::sys::signal::Signal;
let pid = nix::unistd::Pid::from_raw(1);
let status = WaitStatus::from_raw(pid, 0x0002);
assert_eq!(status, Ok(WaitStatus::Signaled(pid, Signal::SIGINT, false)));

Trait Implementations§

source§

impl Clone for WaitStatus

source§

fn clone(&self) -> WaitStatus

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WaitStatus

source§

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

Formats the value using the given formatter. Read more
source§

impl Hash for WaitStatus

source§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<WaitStatus> for WaitStatus

source§

fn eq(&self, other: &WaitStatus) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for WaitStatus

source§

impl Eq for WaitStatus

source§

impl StructuralEq for WaitStatus

source§

impl StructuralPartialEq for WaitStatus

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.