ProcessInfo

Struct ProcessInfo 

Source
pub struct ProcessInfo {
    pub pid: i32,
    pub ppid: i32,
    pub curr_proc: ProcessTask,
    pub curr_io: Option<Io>,
    pub prev_io: Option<Io>,
    pub curr_stat: Option<Stat>,
    pub prev_stat: Option<Stat>,
    pub curr_status: Option<Status>,
    pub interval: Duration,
    pub cwd: PathBuf,
}

Fields§

§pid: i32§ppid: i32§curr_proc: ProcessTask§curr_io: Option<Io>§prev_io: Option<Io>§curr_stat: Option<Stat>§prev_stat: Option<Stat>§curr_status: Option<Status>§interval: Duration§cwd: PathBuf

Implementations§

Source§

impl ProcessInfo

Source

pub fn pid(&self) -> i32

PID of process

Examples found in repository?
examples/sys_demo.rs (line 18)
1fn main() {
2    #[cfg(any(
3        target_os = "android",
4        target_os = "linux",
5        target_os = "macos",
6        target_os = "windows"
7    ))]
8    {
9        let cores = std::thread::available_parallelism()
10            .map(|p| p.get())
11            .unwrap_or(1);
12        for run in 1..=10 {
13            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
14                if proc.cpu_usage() > 0.00001 {
15                    println!(
16                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
17                        run,
18                        proc.pid(),
19                        proc.name(),
20                        proc.status(),
21                        proc.cpu_usage() / cores as f64,
22                        proc.mem_size() / (1024 * 1024),
23                        proc.virtual_size() / (1024 * 1024),
24                        cores,
25                    )
26                }
27            }
28            std::thread::sleep(std::time::Duration::from_millis(1000));
29        }
30    }
31}
Source

pub fn ppid(&self) -> i32

PPID of process

Source

pub fn name(&self) -> String

Name of command

Examples found in repository?
examples/sys_demo.rs (line 19)
1fn main() {
2    #[cfg(any(
3        target_os = "android",
4        target_os = "linux",
5        target_os = "macos",
6        target_os = "windows"
7    ))]
8    {
9        let cores = std::thread::available_parallelism()
10            .map(|p| p.get())
11            .unwrap_or(1);
12        for run in 1..=10 {
13            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
14                if proc.cpu_usage() > 0.00001 {
15                    println!(
16                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
17                        run,
18                        proc.pid(),
19                        proc.name(),
20                        proc.status(),
21                        proc.cpu_usage() / cores as f64,
22                        proc.mem_size() / (1024 * 1024),
23                        proc.virtual_size() / (1024 * 1024),
24                        cores,
25                    )
26                }
27            }
28            std::thread::sleep(std::time::Duration::from_millis(1000));
29        }
30    }
31}
Source

pub fn command(&self) -> String

Full name of command, with arguments

WARNING: As this does no escaping, this function is lossy. It’s OK-ish for display purposes but nothing else.

Source

pub fn cwd(&self) -> String

Source

pub fn status(&self) -> String

Get the status of the process

Examples found in repository?
examples/sys_demo.rs (line 20)
1fn main() {
2    #[cfg(any(
3        target_os = "android",
4        target_os = "linux",
5        target_os = "macos",
6        target_os = "windows"
7    ))]
8    {
9        let cores = std::thread::available_parallelism()
10            .map(|p| p.get())
11            .unwrap_or(1);
12        for run in 1..=10 {
13            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
14                if proc.cpu_usage() > 0.00001 {
15                    println!(
16                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
17                        run,
18                        proc.pid(),
19                        proc.name(),
20                        proc.status(),
21                        proc.cpu_usage() / cores as f64,
22                        proc.mem_size() / (1024 * 1024),
23                        proc.virtual_size() / (1024 * 1024),
24                        cores,
25                    )
26                }
27            }
28            std::thread::sleep(std::time::Duration::from_millis(1000));
29        }
30    }
31}
Source

pub fn cpu_usage(&self) -> f64

CPU usage as a percent of total

Examples found in repository?
examples/sys_demo.rs (line 14)
1fn main() {
2    #[cfg(any(
3        target_os = "android",
4        target_os = "linux",
5        target_os = "macos",
6        target_os = "windows"
7    ))]
8    {
9        let cores = std::thread::available_parallelism()
10            .map(|p| p.get())
11            .unwrap_or(1);
12        for run in 1..=10 {
13            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
14                if proc.cpu_usage() > 0.00001 {
15                    println!(
16                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
17                        run,
18                        proc.pid(),
19                        proc.name(),
20                        proc.status(),
21                        proc.cpu_usage() / cores as f64,
22                        proc.mem_size() / (1024 * 1024),
23                        proc.virtual_size() / (1024 * 1024),
24                        cores,
25                    )
26                }
27            }
28            std::thread::sleep(std::time::Duration::from_millis(1000));
29        }
30    }
31}
Source

pub fn mem_size(&self) -> u64

Memory size in number of bytes

Examples found in repository?
examples/sys_demo.rs (line 22)
1fn main() {
2    #[cfg(any(
3        target_os = "android",
4        target_os = "linux",
5        target_os = "macos",
6        target_os = "windows"
7    ))]
8    {
9        let cores = std::thread::available_parallelism()
10            .map(|p| p.get())
11            .unwrap_or(1);
12        for run in 1..=10 {
13            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
14                if proc.cpu_usage() > 0.00001 {
15                    println!(
16                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
17                        run,
18                        proc.pid(),
19                        proc.name(),
20                        proc.status(),
21                        proc.cpu_usage() / cores as f64,
22                        proc.mem_size() / (1024 * 1024),
23                        proc.virtual_size() / (1024 * 1024),
24                        cores,
25                    )
26                }
27            }
28            std::thread::sleep(std::time::Duration::from_millis(1000));
29        }
30    }
31}
Source

pub fn virtual_size(&self) -> u64

Virtual memory size in bytes

Examples found in repository?
examples/sys_demo.rs (line 23)
1fn main() {
2    #[cfg(any(
3        target_os = "android",
4        target_os = "linux",
5        target_os = "macos",
6        target_os = "windows"
7    ))]
8    {
9        let cores = std::thread::available_parallelism()
10            .map(|p| p.get())
11            .unwrap_or(1);
12        for run in 1..=10 {
13            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
14                if proc.cpu_usage() > 0.00001 {
15                    println!(
16                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
17                        run,
18                        proc.pid(),
19                        proc.name(),
20                        proc.status(),
21                        proc.cpu_usage() / cores as f64,
22                        proc.mem_size() / (1024 * 1024),
23                        proc.virtual_size() / (1024 * 1024),
24                        cores,
25                    )
26                }
27            }
28            std::thread::sleep(std::time::Duration::from_millis(1000));
29        }
30    }
31}

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, 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.