sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
/// System load average values.
#[repr(C)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Debug, Clone, PartialEq)]
pub struct LoadAvg {
    /// Average load over one minute.
    pub one: f64,
    /// Average load over five minutes.
    pub five: f64,
    /// Average load over fifteen minutes.
    pub fifteen: f64,
}

/// Signals on UNIX-like systems.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum Signal {
    /// Hangup detected on the controlling terminal, or death of the controlling process.
    Hangup,
    /// Interrupt from the keyboard.
    Interrupt,
    /// Quit from the keyboard.
    Quit,
    /// Illegal instruction.
    Illegal,
    /// Trace or breakpoint trap.
    Trap,
    /// Abort signal from the C abort function.
    Abort,
    /// IOT trap.
    IOT,
    /// Bus error from a bad memory access.
    Bus,
    /// Floating-point exception.
    FloatingPointException,
    /// Kill signal.
    Kill,
    /// User-defined signal 1.
    User1,
    /// Invalid memory reference.
    Segv,
    /// User-defined signal 2.
    User2,
    /// Broken pipe: write to a pipe with no readers.
    Pipe,
    /// Timer signal from the C alarm function.
    Alarm,
    /// Termination signal.
    Term,
    /// Child stopped or terminated.
    Child,
    /// Continue if stopped.
    Continue,
    /// Stop the process.
    Stop,
    /// Stop typed at the terminal.
    TSTP,
    /// Terminal input for a background process.
    TTIN,
    /// Terminal output for a background process.
    TTOU,
    /// Urgent condition on a socket.
    Urgent,
    /// CPU time limit exceeded.
    XCPU,
    /// File size limit exceeded.
    XFSZ,
    /// Virtual alarm clock.
    VirtualAlarm,
    /// Profiling time expired.
    Profiling,
    /// Windows resize signal.
    Winch,
    /// I/O is now possible.
    IO,
    /// Pollable event (Sys V).
    Poll,
    /// Power failure (System V).
    Power,
    /// Bad argument to a routine (SVr4).
    Sys,
}

impl std::fmt::Display for Signal {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = match *self {
            Self::Hangup => "Hangup",
            Self::Interrupt => "Interrupt",
            Self::Quit => "Quit",
            Self::Illegal => "Illegal",
            Self::Trap => "Trap",
            Self::Abort => "Abort",
            Self::IOT => "IOT",
            Self::Bus => "Bus",
            Self::FloatingPointException => "FloatingPointException",
            Self::Kill => "Kill",
            Self::User1 => "User1",
            Self::Segv => "Segv",
            Self::User2 => "User2",
            Self::Pipe => "Pipe",
            Self::Alarm => "Alarm",
            Self::Term => "Term",
            Self::Child => "Child",
            Self::Continue => "Continue",
            Self::Stop => "Stop",
            Self::TSTP => "TSTP",
            Self::TTIN => "TTIN",
            Self::TTOU => "TTOU",
            Self::Urgent => "Urgent",
            Self::XCPU => "XCPU",
            Self::XFSZ => "XFSZ",
            Self::VirtualAlarm => "VirtualAlarm",
            Self::Profiling => "Profiling",
            Self::Winch => "Winch",
            Self::IO => "IO",
            Self::Poll => "Poll",
            Self::Power => "Power",
            Self::Sys => "Sys",
        };
        f.write_str(s)
    }
}

/// Memory limits for a cgroup.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Debug, Clone, PartialEq)]
pub struct CGroupLimits {
    /// Total memory in bytes for the cgroup.
    pub total_memory: u64,
    /// Free memory in bytes for the cgroup.
    pub free_memory: u64,
    /// Free swap in bytes for the cgroup.
    pub free_swap: u64,
    /// Resident Set Size (RSS) in bytes for the cgroup.
    pub rss: u64,
}

/// Status of a process.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum ProcessStatus {
    /// ## Linux Idle kernel thread.
    Idle,
    /// Process is running.
    Run,
    /// ## Linux Sleeping in an interruptible wait.
    Sleep,
    /// ## Linux Stopped by a signal, or trace-stopped before Linux 2.6.33.
    Stop,
    /// ## Linux/FreeBSD/macOS Zombie process: terminated but not reaped by its parent.
    Zombie,
    /// ## Linux Tracing stop (Linux 2.6.33 onward).
    Tracing,
    /// ## Linux Dead or uninterruptible sleep (usually I/O).
    Dead,
    /// ## Linux Wakekill (Linux 2.6.33 to 3.13 only).
    Wakekill,
    /// ## Linux Waking (Linux 2.6.33 to 3.13 only).
    Waking,
    /// ## Linux Parked (Linux 3.9 to 3.13 only).
    Parked,
    /// ## FreeBSD Blocked on a lock.
    LockBlocked,
    /// ## Linux Waiting in uninterruptible disk sleep.
    UninterruptibleDiskSleep,
    /// ## NetBSD Suspended process.
    Suspended,
    /// Unknown status.
    Unknown(u32),
}

/// Kind of thread.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum ThreadKind {
    /// Kernel thread.
    Kernel,
    /// Thread that runs in userland.
    Userland,
}

/// Errors returned by [`Process::kill_and_wait`][crate::Process::kill_and_wait].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum KillError {
    /// The signal does not exist on this platform.
    SignalDoesNotExist,
    /// The signal could not be sent to the target process.
    FailedToSendSignal,
}

impl core::fmt::Display for KillError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::SignalDoesNotExist => f.write_str("signal does not exist"),
            Self::FailedToSendSignal => f.write_str("failed to send signal"),
        }
    }
}

impl core::error::Error for KillError {}