Module procfs::process [−][src]
Functions and structs related to process information
The primary source of data for functions in this module is the files in a /proc/<pid>/
directory. If you have a process ID, you can use
Process::new(pid)
, otherwise you can get a
list of all running processes using all_processes()
.
In case you have procfs filesystem mounted to a location other than /proc
,
use Process::new_with_root()
.
Examples
Here’s a small example that prints out all processes that are running on the same tty as the calling process. This is very similar to what “ps” does in its default mode. You can run this example yourself with:
cargo run –example=ps
let me = procfs::process::Process::myself().unwrap(); let tps = procfs::ticks_per_second().unwrap(); println!("{: >5} {: <8} {: >8} {}", "PID", "TTY", "TIME", "CMD"); let tty = format!("pty/{}", me.stat.tty_nr().1); for prc in procfs::process::all_processes().unwrap() { if prc.stat.tty_nr == me.stat.tty_nr { // total_time is in seconds let total_time = (prc.stat.utime + prc.stat.stime) as f32 / (tps as f32); println!( "{: >5} {: <8} {: >8} {}", prc.stat.pid, tty, total_time, prc.stat.comm ); } }
Here’s a simple example of how you could get the total memory used by the current process.
There are several ways to do this. For a longer example, see the examples/self_memory.rs
file in the git repository. You can run this example with:
cargo run –example=self_memory
let me = Process::myself().unwrap(); let page_size = procfs::page_size().unwrap() as u64; println!("== Data from /proc/self/stat:"); println!("Total virtual memory used: {} bytes", me.stat.vsize); println!("Total resident set: {} pages ({} bytes)", me.stat.rss, me.stat.rss as u64 * page_size);
Structs
CoredumpFlags | See the coredump_filter() method. |
FDInfo | See the Process::fd() method |
FDPermissions | The mode (read/write permissions) for an open file descriptor |
Io | This struct contains I/O statistics for the process, built from |
Limit | |
Limits | Process limits |
MemoryMap | Represents an entry in a |
MountInfo | Information about a specific mount in a process’s mount namespace. |
MountNFSStatistics | Only NFS mounts provide additional statistics in |
MountStat | Mount information from |
NFSByteCounter | Represents NFS data from |
NFSEventCounter | Represents NFS data from |
NFSOperationStat | Represents NFS data from |
NFSServerCaps | |
Process | Represents a process in |
Stat | Status information about the process, based on the |
StatFlags | Kernel flags for a process |
StatM | Provides information about memory usage, measured in pages. |
Status | Status information about the process, based on the |
Enums
FDTarget | Describes a file descriptor opened by a process. |
LimitValue | |
MMapPath | |
MountOptFields | Optional fields used in MountInfo |
ProcState | Represents the state of a process. |
Functions
all_processes | Return a list of all processes |
Type Definitions
NFSPerOpStats |