proc_tree/types.rs
1//! Data types for the process tree.
2
3/// Process info for a single PID.
4#[derive(Clone, Debug, PartialEq, Eq)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct ProcessInfo {
7 /// Command name (from `/proc/{pid}/comm`).
8 cmd: String,
9 /// Username (from UID lookup via `/etc/passwd`).
10 user: String,
11 /// Parent PID.
12 ppid: u32,
13 /// Thread group ID.
14 tgid: u32,
15 /// Process start time in nanoseconds since boot.
16 /// Used for PID reuse detection.
17 start_time_ns: u64,
18}
19
20impl ProcessInfo {
21 /// Create a new `ProcessInfo`.
22 pub fn new(cmd: String, user: String, ppid: u32, tgid: u32, start_time_ns: u64) -> Self {
23 Self {
24 cmd,
25 user,
26 ppid,
27 tgid,
28 start_time_ns,
29 }
30 }
31
32 /// Command name (from `/proc/{pid}/comm`).
33 pub fn cmd(&self) -> &str {
34 &self.cmd
35 }
36
37 /// Username (from UID lookup via `/etc/passwd`).
38 pub fn user(&self) -> &str {
39 &self.user
40 }
41
42 /// Parent PID.
43 pub fn ppid(&self) -> u32 {
44 self.ppid
45 }
46
47 /// Thread group ID.
48 pub fn tgid(&self) -> u32 {
49 self.tgid
50 }
51
52 /// Process start time in nanoseconds since boot.
53 /// Used for PID reuse detection.
54 pub fn start_time_ns(&self) -> u64 {
55 self.start_time_ns
56 }
57}