1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/// System load average values.
#[repr(C)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Debug, Clone, PartialEq)]
pub struct LoadAvg {
/// Average load over one minute.
pub one: f64,
/// Average load over five minutes.
pub five: f64,
/// Average load over fifteen minutes.
pub fifteen: f64,
}
/// Signals on UNIX-like systems.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum Signal {
/// Hangup detected on the controlling terminal, or death of the controlling process.
Hangup,
/// Interrupt from the keyboard.
Interrupt,
/// Quit from the keyboard.
Quit,
/// Illegal instruction.
Illegal,
/// Trace or breakpoint trap.
Trap,
/// Abort signal from the C abort function.
Abort,
/// IOT trap.
IOT,
/// Bus error from a bad memory access.
Bus,
/// Floating-point exception.
FloatingPointException,
/// Kill signal.
Kill,
/// User-defined signal 1.
User1,
/// Invalid memory reference.
Segv,
/// User-defined signal 2.
User2,
/// Broken pipe: write to a pipe with no readers.
Pipe,
/// Timer signal from the C alarm function.
Alarm,
/// Termination signal.
Term,
/// Child stopped or terminated.
Child,
/// Continue if stopped.
Continue,
/// Stop the process.
Stop,
/// Stop typed at the terminal.
TSTP,
/// Terminal input for a background process.
TTIN,
/// Terminal output for a background process.
TTOU,
/// Urgent condition on a socket.
Urgent,
/// CPU time limit exceeded.
XCPU,
/// File size limit exceeded.
XFSZ,
/// Virtual alarm clock.
VirtualAlarm,
/// Profiling time expired.
Profiling,
/// Windows resize signal.
Winch,
/// I/O is now possible.
IO,
/// Pollable event (Sys V).
Poll,
/// Power failure (System V).
Power,
/// Bad argument to a routine (SVr4).
Sys,
}
impl std::fmt::Display for Signal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match *self {
Self::Hangup => "Hangup",
Self::Interrupt => "Interrupt",
Self::Quit => "Quit",
Self::Illegal => "Illegal",
Self::Trap => "Trap",
Self::Abort => "Abort",
Self::IOT => "IOT",
Self::Bus => "Bus",
Self::FloatingPointException => "FloatingPointException",
Self::Kill => "Kill",
Self::User1 => "User1",
Self::Segv => "Segv",
Self::User2 => "User2",
Self::Pipe => "Pipe",
Self::Alarm => "Alarm",
Self::Term => "Term",
Self::Child => "Child",
Self::Continue => "Continue",
Self::Stop => "Stop",
Self::TSTP => "TSTP",
Self::TTIN => "TTIN",
Self::TTOU => "TTOU",
Self::Urgent => "Urgent",
Self::XCPU => "XCPU",
Self::XFSZ => "XFSZ",
Self::VirtualAlarm => "VirtualAlarm",
Self::Profiling => "Profiling",
Self::Winch => "Winch",
Self::IO => "IO",
Self::Poll => "Poll",
Self::Power => "Power",
Self::Sys => "Sys",
};
f.write_str(s)
}
}
/// Memory limits for a cgroup.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Debug, Clone, PartialEq)]
pub struct CGroupLimits {
/// Total memory in bytes for the cgroup.
pub total_memory: u64,
/// Free memory in bytes for the cgroup.
pub free_memory: u64,
/// Free swap in bytes for the cgroup.
pub free_swap: u64,
/// Resident Set Size (RSS) in bytes for the cgroup.
pub rss: u64,
}
/// Status of a process.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum ProcessStatus {
/// ## Linux Idle kernel thread.
Idle,
/// Process is running.
Run,
/// ## Linux Sleeping in an interruptible wait.
Sleep,
/// ## Linux Stopped by a signal, or trace-stopped before Linux 2.6.33.
Stop,
/// ## Linux/FreeBSD/macOS Zombie process: terminated but not reaped by its parent.
Zombie,
/// ## Linux Tracing stop (Linux 2.6.33 onward).
Tracing,
/// ## Linux Dead or uninterruptible sleep (usually I/O).
Dead,
/// ## Linux Wakekill (Linux 2.6.33 to 3.13 only).
Wakekill,
/// ## Linux Waking (Linux 2.6.33 to 3.13 only).
Waking,
/// ## Linux Parked (Linux 3.9 to 3.13 only).
Parked,
/// ## FreeBSD Blocked on a lock.
LockBlocked,
/// ## Linux Waiting in uninterruptible disk sleep.
UninterruptibleDiskSleep,
/// ## NetBSD Suspended process.
Suspended,
/// Unknown status.
Unknown(u32),
}
/// Kind of thread.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum ThreadKind {
/// Kernel thread.
Kernel,
/// Thread that runs in userland.
Userland,
}
/// Errors returned by [`Process::kill_and_wait`][crate::Process::kill_and_wait].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum KillError {
/// The signal does not exist on this platform.
SignalDoesNotExist,
/// The signal could not be sent to the target process.
FailedToSendSignal,
}
impl core::fmt::Display for KillError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::SignalDoesNotExist => f.write_str("signal does not exist"),
Self::FailedToSendSignal => f.write_str("failed to send signal"),
}
}
}
impl core::error::Error for KillError {}