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
//! The FreeBSD backend.
//!
//! FreeBSD has no `/proc` by default (`procfs(5)` is deprecated and often not
//! mounted), so the data comes from `sysctl` and `libkvm`, which is the same pair
//! htop uses in `freebsd/`:
//!
//! | Need | Source |
//! |---|---|
//! | Process list | `sysctl(KERN_PROC_ALL)` → `kinfo_proc[]` |
//! | Per-process CPU, memory, faults | the same `kinfo_proc` |
//! | Command line | `sysctl(KERN_PROC_ARGS)` |
//! | Executable path | `sysctl(KERN_PROC_PATHNAME)` |
//! | Working directory | `sysctl(KERN_PROC_CWD)` |
//! | Threads | `kvm_getprocs(KERN_PROC_INC_THREAD)` |
//! | Per-core CPU ticks | `sysctl(KERN_CPTIME)` / `kvm_getpcpu` |
//! | Memory pages | `sysctl(VM_TOTAL)` → `struct vmtotal` |
//! | Swap | `kvm_getswapinfo(3)` |
//! | Load average | `getloadavg(3)` |
//! | Boot time | `sysctl(KERN_BOOTTIME)` |
//! | Network | `sysctl(NET_RT_IFLIST)` → `if_msghdr` |
//! | Disk | `devstat_getdevs(3)` |
//!
//! # Why `kinfo_proc` is used directly here
//!
//! The macOS backend cannot use `kinfo_proc` because `libc` does not expose
//! Darwin's version, so it reads fixed offsets out of raw bytes. `libc` *does*
//! declare FreeBSD's `kinfo_proc`, and the layout is stable within an ABI
//! version, so this backend uses the struct and lets the compiler do the offsets.
//! `kinfo::validate()` still checks the result against `sysctl` at runtime.
/// Conversions and constants that are easy to get wrong, in one place.
;