procfs_core::process

Struct Stat

source
#[non_exhaustive]
pub struct Stat {
Show 52 fields pub pid: i32, pub comm: String, pub state: char, pub ppid: i32, pub pgrp: i32, pub session: i32, pub tty_nr: i32, pub tpgid: i32, pub flags: u32, pub minflt: u64, pub cminflt: u64, pub majflt: u64, pub cmajflt: u64, pub utime: u64, pub stime: u64, pub cutime: i64, pub cstime: i64, pub priority: i64, pub nice: i64, pub num_threads: i64, pub itrealvalue: i64, pub starttime: u64, pub vsize: u64, pub rss: u64, pub rsslim: u64, pub startcode: u64, pub endcode: u64, pub startstack: u64, pub kstkesp: u64, pub kstkeip: u64, pub signal: u64, pub blocked: u64, pub sigignore: u64, pub sigcatch: u64, pub wchan: u64, pub nswap: u64, pub cnswap: u64, pub exit_signal: Option<i32>, pub processor: Option<i32>, pub rt_priority: Option<u32>, pub policy: Option<u32>, pub delayacct_blkio_ticks: Option<u64>, pub guest_time: Option<u64>, pub cguest_time: Option<i64>, pub start_data: Option<u64>, pub end_data: Option<u64>, pub start_brk: Option<u64>, pub arg_start: Option<u64>, pub arg_end: Option<u64>, pub env_start: Option<u64>, pub env_end: Option<u64>, pub exit_code: Option<i32>,
}
Expand description

Status information about the process, based on the /proc/<pid>/stat file.

Not all fields are available in every kernel. These fields have Option<T> types.

New fields to this struct may be added at any time (even without a major or minor semver bump).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§pid: i32

The process ID.

§comm: String

The filename of the executable, without the parentheses.

This is visible whether or not the executable is swapped out.

Note that if the actual comm field contains invalid UTF-8 characters, they will be replaced here by the U+FFFD replacement character.

§state: char

Process State.

See state() to get the process state as an enum.

§ppid: i32

The PID of the parent of this process.

§pgrp: i32

The process group ID of the process.

§session: i32

The session ID of the process.

§tty_nr: i32

The controlling terminal of the process.

The minor device number is contained in the combination of bits 31 to 20 and 7 to 0; the major device number is in bits 15 to 8.

See tty_nr() to get this value decoded into a (major, minor) tuple

§tpgid: i32

The ID of the foreground process group of the controlling terminal of the process.

§flags: u32

The kernel flags word of the process.

For bit meanings, see the PF_* defines in the Linux kernel source file include/linux/sched.h.

See flags() to get a StatFlags bitfield object.

§minflt: u64

The number of minor faults the process has made which have not required loading a memory page from disk.

§cminflt: u64

The number of minor faults that the process’s waited-for children have made.

§majflt: u64

The number of major faults the process has made which have required loading a memory page from disk.

§cmajflt: u64

The number of major faults that the process’s waited-for children have made.

§utime: u64

Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by ticks_per_second()).

This includes guest time, guest_time (time spent running a virtual CPU, see below), so that applications that are not aware of the guest time field do not lose that time from their calculations.

§stime: u64

Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by ticks_per_second()).

§cutime: i64

Amount of time that this process’s waited-for children have been scheduled in user mode, measured in clock ticks (divide by ticks_per_second()).

This includes guest time, cguest_time (time spent running a virtual CPU, see below).

§cstime: i64

Amount of time that this process’s waited-for children have been scheduled in kernel mode, measured in clock ticks (divide by ticks_per_second()).

§priority: i64

For processes running a real-time scheduling policy (policy below; see sched_setscheduler(2)), this is the negated scheduling priority, minus one;

That is, a number in the range -2 to -100, corresponding to real-time priority 1 to 99. For processes running under a non-real-time scheduling policy, this is the raw nice value (setpriority(2)) as represented in the kernel. The kernel stores nice values as numbers in the range 0 (high) to 39 (low), corresponding to the user-visible nice range of -20 to 19. (This explanation is for Linux 2.6)

Before Linux 2.6, this was a scaled value based on the scheduler weighting given to this process.

§nice: i64

The nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority).

§num_threads: i64

Number of threads in this process (since Linux 2.6). Before kernel 2.6, this field was hard coded to 0 as a placeholder for an earlier removed field.

§itrealvalue: i64

The time in jiffies before the next SIGALRM is sent to the process due to an interval timer.

Since kernel 2.6.17, this field is no longer maintained, and is hard coded as 0.

§starttime: u64

The time the process started after system boot.

In kernels before Linux 2.6, this value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock ticks (divide by sysconf(_SC_CLK_TCK)).

See also the Stat::starttime() method to get the starttime as a DateTime object

§vsize: u64

Virtual memory size in bytes.

§rss: u64

Resident Set Size: number of pages the process has in real memory.

This is just the pages which count toward text, data, or stack space. This does not include pages which have not been demand-loaded in, or which are swapped out.

§rsslim: u64

Current soft limit in bytes on the rss of the process; see the description of RLIMIT_RSS in getrlimit(2).

§startcode: u64

The address above which program text can run.

§endcode: u64

The address below which program text can run.

§startstack: u64

The address of the start (i.e., bottom) of the stack.

§kstkesp: u64

The current value of ESP (stack pointer), as found in the kernel stack page for the process.

§kstkeip: u64

The current EIP (instruction pointer).

§signal: u64

The bitmap of pending signals, displayed as a decimal number. Obsolete, because it does not provide information on real-time signals; use /proc/<pid>/status instead.

§blocked: u64

The bitmap of blocked signals, displayed as a decimal number. Obsolete, because it does not provide information on real-time signals; use /proc/<pid>/status instead.

§sigignore: u64

The bitmap of ignored signals, displayed as a decimal number. Obsolete, because it does not provide information on real-time signals; use /proc/<pid>/status instead.

§sigcatch: u64

The bitmap of caught signals, displayed as a decimal number. Obsolete, because it does not provide information on real-time signals; use /proc/<pid>/status instead.

§wchan: u64

This is the “channel” in which the process is waiting. It is the address of a location in the kernel where the process is sleeping. The corresponding symbolic name can be found in /proc/<pid>/wchan.

§nswap: u64

Number of pages swapped (not maintained).

§cnswap: u64

Cumulative nswap for child processes (not maintained).

§exit_signal: Option<i32>

Signal to be sent to parent when we die.

(since Linux 2.1.22)

§processor: Option<i32>

CPU number last executed on.

(since Linux 2.2.8)

§rt_priority: Option<u32>

Real-time scheduling priority

Real-time scheduling priority, a number in the range 1 to 99 for processes scheduled under a real-time policy, or 0, for non-real-time processes

(since Linux 2.5.19)

§policy: Option<u32>

Scheduling policy (see sched_setscheduler(2)).

Decode using the SCHED_* constants in linux/sched.h.

(since Linux 2.5.19)

§delayacct_blkio_ticks: Option<u64>

Aggregated block I/O delays, measured in clock ticks (centiseconds).

(since Linux 2.6.18)

§guest_time: Option<u64>

Guest time of the process (time spent running a virtual CPU for a guest operating system), measured in clock ticks (divide by ticks_per_second())

(since Linux 2.6.24)

§cguest_time: Option<i64>

Guest time of the process’s children, measured in clock ticks (divide by ticks_per_second()).

(since Linux 2.6.24)

§start_data: Option<u64>

Address above which program initialized and uninitialized (BSS) data are placed.

(since Linux 3.3)

§end_data: Option<u64>

Address below which program initialized and uninitialized (BSS) data are placed.

(since Linux 3.3)

§start_brk: Option<u64>

Address above which program heap can be expanded with brk(2).

(since Linux 3.3)

§arg_start: Option<u64>

Address above which program command-line arguments (argv) are placed.

(since Linux 3.5)

§arg_end: Option<u64>

Address below program command-line arguments (argv) are placed.

(since Linux 3.5)

§env_start: Option<u64>

Address above which program environment is placed.

(since Linux 3.5)

§env_end: Option<u64>

Address below which program environment is placed.

(since Linux 3.5)

§exit_code: Option<i32>

The thread’s exit status in the form reported by waitpid(2).

(since Linux 3.5)

Implementations§

source§

impl Stat

source

pub fn state(&self) -> ProcResult<ProcState>

source

pub fn tty_nr(&self) -> (i32, i32)

source

pub fn flags(&self) -> ProcResult<StatFlags>

The kernel flags word of the process, as a bitfield

See also the Stat::flags field.

source

pub fn starttime( &self, ) -> impl WithSystemInfo<'_, Output = ProcResult<DateTime<Local>>>

Get the starttime of the process as a DateTime object.

See also the starttime field.

This function requires the “chrono” features to be enabled (which it is by default).

Since computing the absolute start time requires knowing the current boot time, this function returns a type that needs info about the current machine.

§Example
use procfs::WithCurrentSystemInfo;

let me = procfs::process::Process::myself().unwrap();
let stat = me.stat().unwrap();
let start = stat.starttime().get().unwrap();
source

pub fn rss_bytes(&self) -> impl WithSystemInfo<'_, Output = u64>

Gets the Resident Set Size (in bytes)

The rss field will return the same value in pages

§Example

Calculating the rss value in bytes requires knowing the page size, so a SystemInfo is needed.

use procfs::WithCurrentSystemInfo;

let me = procfs::process::Process::myself().unwrap();
let stat = me.stat().unwrap();
let bytes = stat.rss_bytes().get();

Trait Implementations§

source§

impl Clone for Stat

source§

fn clone(&self) -> Stat

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 Stat

source§

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

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

impl<'de> Deserialize<'de> for Stat

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl FromRead for Stat

source§

fn from_read<R: Read>(r: R) -> ProcResult<Self>

Read the type from a Read.
source§

fn from_file<P: AsRef<Path>>(path: P) -> ProcResult<Self>

Read the type from a file.
source§

impl Serialize for Stat

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Stat

§

impl RefUnwindSafe for Stat

§

impl Send for Stat

§

impl Sync for Stat

§

impl Unpin for Stat

§

impl UnwindSafe for Stat

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 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> ToOwned for T
where T: Clone,

source§

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 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,