Enum WaitStatus

enum WaitStatus

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(crate::unistd::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(crate::unistd::Pid, crate::sys::signal::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(crate::unistd::Pid, crate::sys::signal::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).

PtraceEvent(crate::unistd::Pid, crate::sys::signal::Signal, libc::c_int)

The traced process was stopped by a PTRACE_EVENT_* event. See nix::sys::ptrace and ptrace(2) for more information. All currently-defined events use SIGTRAP as the signal; the third field is the PTRACE_EVENT_* value of the event.

PtraceSyscall(crate::unistd::Pid)

The traced process was stopped by execution of a system call, and PTRACE_O_TRACESYSGOOD is in effect. See ptrace(2) for more information.

Continued(crate::unistd::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

impl WaitStatus

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

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)));

impl WaitStatus

fn pid(self: &Self) -> Option<Pid>

Extracts the PID from the WaitStatus unless it equals StillAlive.

impl Clone for WaitStatus

fn clone(self: &Self) -> WaitStatus

impl Copy for WaitStatus

impl Debug for WaitStatus

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

impl Eq for WaitStatus

impl Freeze for WaitStatus

impl Hash for WaitStatus

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl PartialEq for WaitStatus

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

impl RefUnwindSafe for WaitStatus

impl Send for WaitStatus

impl StructuralPartialEq for WaitStatus

impl Sync for WaitStatus

impl Unpin for WaitStatus

impl UnsafeUnpin for WaitStatus

impl UnwindSafe for WaitStatus

impl<T> Any for WaitStatus

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for WaitStatus

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for WaitStatus

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for WaitStatus

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for WaitStatus

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for WaitStatus

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for WaitStatus

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for WaitStatus

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for WaitStatus

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>