linux_procfs/
pidentries.rs

1use super::Pid;
2
3#[derive(Debug, Default, Clone)]
4pub struct PidEntries {
5    pub pidentries: Vec<PidEntry>,
6}
7
8#[derive(Debug, Default, Clone)]
9pub struct PidEntry {
10    pub is_empty: bool,
11    pub stat: PidStat,
12    pub statm: PidStatm,
13    pub status: PidStatus,
14    pub cmdline: PidCmdline,
15}
16
17// /proc/[number]/stat
18#[derive(Debug, Default, Clone)]
19pub struct PidStat {
20    pub pid: Pid, // process id
21
22    #[cfg(feature = "has_pidentry_stat_comm")]
23    pub comm: String, // filename of executable
24    #[cfg(feature = "has_pidentry_stat_state")]
25    pub state: u8, // process state character ('S':sleeping, 'R', 'D', 'Z', 'T')
26    //
27    pub ppid: Pid, // pid of parent process
28    pub pgrp: i32, // process groud id
29    //
30    #[cfg(feature = "has_pidentry_stat_session")]
31    pub session: i32, // session id
32    #[cfg(feature = "has_pidentry_stat_tty_nr")]
33    pub tty_nr: i32, // device number of terminal the process uses
34    #[cfg(feature = "has_pidentry_stat_tpgid")]
35    pub tpgid: i32, // terminal process group id
36    //
37    #[cfg(feature = "has_pidentry_stat_flags")]
38    pub flags: u32, // kernel flags of process
39    #[cfg(feature = "has_pidentry_stat_minflt")]
40    pub minflt: u32, // count of minor page faults since process start
41    #[cfg(feature = "has_pidentry_stat_cminflt")]
42    pub cminflt: u32, // cumulative minflt of process and child processes
43    #[cfg(feature = "has_pidentry_stat_majflt")]
44    pub majflt: u32, // count of major page faults since process start
45    #[cfg(feature = "has_pidentry_stat_cmajflt")]
46    pub cmajflt: u32, // cumulative majflt of process and child processes
47    //
48    pub utime: u32,  // user-mode cpu time (clock_t, see also man 2 times)
49    pub stime: u32,  // system-mode cpu time
50    pub cutime: u32, // cumulative utime of process and child processes
51    pub cstime: u32, // cumulative stime of process and child processes
52    //
53    #[cfg(feature = "has_pidentry_stat_priority")]
54    pub priority: i8, // cpu resource priority of process [>=0]
55    //
56    pub nice: i8,         // nice value ranges from 19 to -19.
57    pub num_threads: i32, // count of threads of process (from linux v2.6)
58    pub starttime: u64,   // start time of process
59    //
60    #[cfg(feature = "has_pidentry_stat_vsize")]
61    pub vsize: usize, // *virtual memory size in bytes
62    #[cfg(feature = "has_pidentry_stat_rss")]
63    pub rss: usize, //  resident set size
64    #[cfg(feature = "has_pidentry_stat_rlim")]
65    pub rlim: usize, // *current limit in bytes on the rss of the process
66    //
67    #[cfg(feature = "has_pidentry_stat_startcode")]
68    pub startcode: usize, //  addresst of beginning of code segment
69    #[cfg(feature = "has_pidentry_stat_endcode")]
70    pub endcode: usize, //  address of end of code segment
71    #[cfg(feature = "has_pidentry_stat_startstack")]
72    pub startstack: usize, // *address of the bottom of stack for the process
73    #[cfg(feature = "has_pidentry_stat_kstesp")]
74    pub kstesp: usize, // *kernel stack pointer
75    #[cfg(feature = "has_pidentry_stat_ksteip")]
76    pub ksteip: usize, //  kernel instruction pointer
77    //
78    #[cfg(feature = "has_pidentry_stat_signal")]
79    pub signal: u32, // bitmap of pending signals
80    #[cfg(feature = "has_pidentry_stat_blocked")]
81    pub blocked: u32, // bitmap of blocked signals
82    #[cfg(feature = "has_pidentry_stat_sigignore")]
83    pub sigignore: u32, // bitmap of ignored signals
84    #[cfg(feature = "has_pidentry_stat_sigcatch")]
85    pub sigcatch: u32, // bitmap of caught signals
86    //
87    #[cfg(feature = "has_pidentry_stat_exit_signal")]
88    pub exit_signal: i32, // signal to be sent to parent when this process die, (linux v2.1.22)
89    #[cfg(feature = "has_pidentry_stat_processor")]
90    pub processor: i32, // cpu number last executed on. (linux v2.2.8)
91    #[cfg(feature = "has_pidentry_stat_rt_priority")]
92    pub rt_priority: u32, // real-time scheduling priority (linux v2.5.19)
93    #[cfg(feature = "has_pidentry_stat_policy")]
94    pub policy: u32, // scheduling policy (linux v2.5.19)
95    #[cfg(feature = "has_pidentry_stat_delayacct")]
96    pub delayacct_blkio_ticks: u64, // delay clock ticks of block io (linux v2.6.18)
97}
98
99// /proc/[number]/statm
100#[derive(Debug, Default, Clone)]
101pub struct PidStatm {
102    pub size: u32,     // total number of pages of memory
103    pub resident: u32, // number of resident set (non-swapped) pages
104    pub share: u32,    // number of pages of shared (mmaped) pages
105    pub text: u32,     // text resident set size
106    pub lib: u32,      // shared0lib resident set size
107    pub data: u32,     // data/stack resident set size
108}
109
110// /proc/[number]/status
111#[derive(Debug, Default, Clone)]
112pub struct PidStatus {
113    #[cfg(feature = "has_pidentry_status_name")]
114    pub name: String,
115    //
116    #[cfg(feature = "has_pidentry_status_state")]
117    pub state: u8,
118    //
119    #[cfg(feature = "has_pidentry_status_tgid")]
120    pub tgid: Pid,
121    #[cfg(feature = "has_pidentry_status_ngid")]
122    pub ngid: Pid,
123    //
124    pub pid: Pid,
125    pub ppid: Pid,
126    //
127    #[cfg(feature = "has_pidentry_status_tracer_pid")]
128    pub tracer_pid: Pid,
129    //
130    // Uid
131    pub ruid: u32, // real user id
132    pub euid: u32, // effective user id
133    pub suid: u32, // saved user id
134    pub fuid: u32, // filesystem user id
135    // Gid
136    pub rgid: u32, // real group id
137    pub egid: u32, // effective group id
138    pub sgid: u32, // saved group id
139    pub fgid: u32, // filesystem group id
140    //
141    #[cfg(feature = "has_pidentry_status_vm_peak")]
142    pub vm_peak: usize,
143    //
144    pub vm_size: usize, // same as vsize in kb
145    pub vm_lck: usize,  // locked pages in kb
146    //{{{  >= linux v3.2
147    #[cfg(feature = "has_pidentry_status_vm_pin")]
148    pub vm_pin: usize, //
149    //}}}
150    //
151    #[cfg(feature = "has_pidentry_status_vm_hwm")]
152    pub vm_hwm: usize,
153    //
154    pub vm_rss: usize, // same as rss in kb
155    //
156    //{{{  >= linux v4.5
157    #[cfg(feature = "has_pidentry_status_rss_anon")]
158    pub rss_anon: usize,
159    #[cfg(feature = "has_pidentry_status_rss_file")]
160    pub rss_file: usize,
161    #[cfg(feature = "has_pidentry_status_rss_shmem")]
162    pub rss_shmem: usize,
163    //}}}
164    //
165    pub vm_data: usize, // data size in kb
166    pub vm_stk: usize,  // stack size in kb
167    pub vm_exe: usize,  // executable size in kb
168    pub vm_lib: usize,  // library size in kb (all pages, not just used ones)
169    pub vm_pte: usize,  //
170    //
171    //{{{  >= linux v4.1
172    #[cfg(feature = "has_pidentry_status_vm_pmd")]
173    pub vm_pmd: usize,
174    //}}}
175    //
176    //{{{  >= linux v2.6.34
177    pub vm_swap: usize,
178    //}}}
179}
180
181// /proc/[number]/comm
182// /proc/[number]/cmdline
183#[derive(Debug, Default, Clone)]
184pub struct PidCmdline {
185    pub cmdline: String,
186}