| 1 |
.\" |
| 2 |
.\" Copyright (c) 2020-2026 Jim Warner <[email protected]> |
| 3 |
.\" Copyright (c) 2020-2024 Craig Small <[email protected]> |
| 4 |
.\" |
| 5 |
.\" This manual is free software; you can redistribute it and/or |
| 6 |
.\" modify it under the terms of the GNU Lesser General Public |
| 7 |
.\" License as published by the Free Software Foundation; either |
| 8 |
.\" version 2.1 of the License, or (at your option) any later version. |
| 9 |
.\" |
| 10 |
.\" |
| 11 |
.TH PROCPS 3 2026-03-03 procps-ng |
| 12 |
.\" Please adjust this date whenever revising the manpage. |
| 13 |
.\" |
| 14 |
.nh |
| 15 |
.SH NAME |
| 16 |
procps \- API to access system level information in the /proc filesystem |
| 17 |
.SH SYNOPSIS |
| 18 |
Five distinct interfaces are represented in this synopsis and named after |
| 19 |
the files they access in the /proc pseudo filesystem: |
| 20 |
.BR diskstats ", " meminfo ", " slabinfo ", " stat " and " vmstat . |
| 21 |
.nf |
| 22 |
.RS +4 |
| 23 |
#include <libproc2/\fBnamed_interface\fR.h> |
| 24 |
.P |
| 25 |
.RI "int\fB procps_new \fR (struct info **" info ); |
| 26 |
.RI "int\fB procps_ref \fR (struct info *" info ); |
| 27 |
.RI "int\fB procps_unref\fR (struct info **" info ); |
| 28 |
.P |
| 29 |
.RB "struct result *" procps_get " (" |
| 30 |
.RI " struct info *" info , |
| 31 |
.RI "[ const char *" name ", ] \fBdiskstats\fR api only" |
| 32 |
.RI " enum item " item ); |
| 33 |
.P |
| 34 |
.RB "struct stack *" procps_select " (" |
| 35 |
.RI " struct info *" info , |
| 36 |
.RI "[ const char *" name ", ] \fBdiskstats\fR api only" |
| 37 |
.RI " enum item *" items , |
| 38 |
.RI " int " numitems ); |
| 39 |
.P |
| 40 |
.RB "struct reaped *" procps_reap " (" |
| 41 |
.RI " struct info *" info , |
| 42 |
.RI "[ enum reap_type " what ", ] \fBstat\fR api only" |
| 43 |
.RI " enum item *" items , |
| 44 |
.RI " int " numitems ); |
| 45 |
.P |
| 46 |
.RB "struct stack **" procps_sort " (" |
| 47 |
.RI " struct info *" info , |
| 48 |
.RI " struct stack *" stacks [], |
| 49 |
.RI " int " numstacked , |
| 50 |
.RI " enum item " sortitem , |
| 51 |
.RI " enum sort_order " order ); |
| 52 |
.fi |
| 53 |
.P |
| 54 |
The above functions and structures are generic but the specific |
| 55 |
\fBnamed_interface\fR would also be part of any identifiers. |
| 56 |
For example, |
| 57 |
\[oq]procps_new\[cq] would actually be |
| 58 |
\[oq]procps_\fBmeminfo\fR_new\[cq] and \[oq]info\[cq] would really be |
| 59 |
\[oq]\fBdiskstats\fR_info\[cq], etc. |
| 60 |
.P |
| 61 |
The same \fBnamed_interface\fR is used in each header file name with |
| 62 |
an appended \[oq].h\[cq] suffix. |
| 63 |
.P |
| 64 |
Link with \fI\-lproc2\fP. |
| 65 |
.SH DESCRIPTION |
| 66 |
.SS Overview |
| 67 |
Central to these interfaces is a simple \[oq]result\[cq] |
| 68 |
structure reflecting an \[oq]item\[cq] plus its value (in a union |
| 69 |
with standard C language types as members). |
| 70 |
All \[oq]result\[cq] structures are automatically allocated and |
| 71 |
provided by the library. |
| 72 |
.P |
| 73 |
By specifying an array of \[oq]items\[cq], these structures can be |
| 74 |
organized as a \[oq]stack\[cq], potentially yielding many results |
| 75 |
with a single function call. |
| 76 |
Thus, a \[oq]stack\[cq] can be viewed as a variable length record |
| 77 |
whose content and order is determined solely by the user. |
| 78 |
.P |
| 79 |
As part of each interface there are two unique enumerators. |
| 80 |
The \[oq]noop\[cq] and \[oq]extra\[cq] items exist to hold user values. |
| 81 |
They are never set by the library, but the \[oq]extra\[cq] |
| 82 |
result will be zeroed with each library interaction. |
| 83 |
.P |
| 84 |
The \fBnamed_interface\fR header file will be an essential |
| 85 |
document during user program development. |
| 86 |
There you will find available items, their return type |
| 87 |
(the \[oq]result\[cq] struct member name) and the source for such values. |
| 88 |
Additional enumerators and structures are also documented there. |
| 89 |
.P |
| 90 |
.SS Usage |
| 91 |
The following would be a typical sequence of calls to |
| 92 |
these interfaces. |
| 93 |
.P |
| 94 |
.nf |
| 95 |
.RB "1. " procps_new() |
| 96 |
.RB "2. " procps_get() ", " procps_select() " or " procps_reap() |
| 97 |
.RB "3. " procps_unref() |
| 98 |
.fi |
| 99 |
.P |
| 100 |
The \fBget\fR function is used to retrieve a \[oq]result\[cq] structure |
| 101 |
for a single \[oq]item\[cq]. |
| 102 |
Alternatively, a \fBGET\fR macro is available when only the return |
| 103 |
value is of interest. |
| 104 |
.P |
| 105 |
The \fBselect\fR function can retrieve multiple \[oq]result\[cq] |
| 106 |
structures in a single \[oq]stack\[cq]. |
| 107 |
.P |
| 108 |
For unpredictable variable outcomes, the \fBdiskstats\fR, \fBslabinfo\fR |
| 109 |
and \fBstat\fR interfaces export a \fBreap\fR function. |
| 110 |
It is used to retrieve multiple \[oq]stacks\[cq] each containing |
| 111 |
multiple \[oq]result\[cq] structures. |
| 112 |
Optionally, a user may choose to \fBsort\fR those results. |
| 113 |
.P |
| 114 |
To exploit any \[oq]stack\[cq], |
| 115 |
and access individual \[oq]result\[cq] structures, |
| 116 |
a \fIrelative_enum\fR is required as shown in the \fBVAL\fR macro |
| 117 |
defined in the header file. |
| 118 |
Such values could be hard coded as: 0 through numitems-1. |
| 119 |
However, this need is typically satisfied by creating your own |
| 120 |
enumerators corresponding to the order of the \[oq]items\[cq] array. |
| 121 |
.SS Caveats |
| 122 |
The \fBnew\fR, \fBref\fR, \fBunref\fR, \fBget\fR and \fBselect\fR |
| 123 |
functions are available in all five interfaces. |
| 124 |
.P |
| 125 |
For the \fBnew\fR and \fBunref\fR functions, the address of an \fIinfo\fR |
| 126 |
struct pointer must be supplied. |
| 127 |
With \fBnew\fR it must have been initialized to NULL. |
| 128 |
With \fBunref\fR it will be reset to NULL if the reference count reaches zero. |
| 129 |
.P |
| 130 |
In the case of the \fBdiskstats\fR interface, a \fIname\fR parameter |
| 131 |
on the \fBget\fR and \fBselect\fR functions identifies a disk or |
| 132 |
partition name |
| 133 |
.P |
| 134 |
With the \fBslabinfo\fR interface, \fIselect\fR results are only |
| 135 |
meaningful with \[oq]SLABS\[cq] (plural) enumerators while \fIreap\fR |
| 136 |
results are only meaningful with \[oq]SLAB\[cq] (singular) enumerators. |
| 137 |
.P |
| 138 |
For the \fBstat\fR interface, a \fIwhat\fR parameter on the \fBreap\fR |
| 139 |
function identifies whether data for just CPUs or both CPUs and NUMA |
| 140 |
nodes is to be gathered. |
| 141 |
.P |
| 142 |
When using the \fBsort\fR function, the parameters \fIstacks\fR and |
| 143 |
\fInumstacked\fR would normally be those returned in the |
| 144 |
\[oq]reaped\[cq] structure. |
| 145 |
.SH RETURN VALUE |
| 146 |
.SS Functions Returning an \[oq]int\[cq] |
| 147 |
An error will be indicated by a negative number that |
| 148 |
is always the inverse of some well known errno.h value. |
| 149 |
.P |
| 150 |
Success is indicated by a zero return value. |
| 151 |
However, the \fBref\fR and \fBunref\fR functions return |
| 152 |
the current \fIinfo\fR structure reference count. |
| 153 |
.SS Functions Returning an \[oq]address\[cq] |
| 154 |
An error will be indicated by a NULL return pointer |
| 155 |
with the reason found in the formal errno value. |
| 156 |
.P |
| 157 |
Success is indicated by a pointer to the named structure. |
| 158 |
.SH DEBUGGING |
| 159 |
To aid in program development, there is a provision that can |
| 160 |
help ensure \[oq]result\[cq] member references agree with library |
| 161 |
expectations. |
| 162 |
It assumes that a supplied macro in the header file is |
| 163 |
used to access the \[oq]result\[cq] value. |
| 164 |
.P |
| 165 |
This feature can be activated through either of the following |
| 166 |
methods and any discrepancies will be written to \fBstderr\fR. |
| 167 |
.IP 1) 3 |
| 168 |
Add CFLAGS='-DXTRA_PROCPS_DEBUG' to any other ./configure |
| 169 |
options employed. |
| 170 |
.IP 2) 3 |
| 171 |
Add #include <libproc2/xtra-procps-debug.h> to any program |
| 172 |
\fIafter\fR the named interface includes. |
| 173 |
.PP |
| 174 |
This verification feature incurs substantial overhead. |
| 175 |
Therefore, it is important that it \fInot\fR be activated |
| 176 |
for a production/release build. |
| 177 |
.SH SEE ALSO |
| 178 |
.BR procps_misc (3), |
| 179 |
.BR procps_pids (3), |
| 180 |
.BR proc (5). |