2021-01-14 11:30:00 +05:30
|
|
|
.\" (C) Copyright 2020-2021 Jim Warner <warnerjc@comcast.net>
|
2020-05-19 18:13:21 +05:30
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(LGPL_2.1+)
|
|
|
|
.\" This manual is free software; you can redistribute it and/or
|
|
|
|
.\" modify it under the terms of the GNU Lesser General Public
|
|
|
|
.\" License as published by the Free Software Foundation; either
|
|
|
|
.\" version 2.1 of the License, or (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\" This manual is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
.\" Lesser General Public License for more details.
|
|
|
|
.\"
|
|
|
|
.\" You should have received a copy of the GNU Lesser General Public
|
|
|
|
.\" License along with this library; if not, write to the Free Software
|
|
|
|
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
2021-02-16 11:30:00 +05:30
|
|
|
.TH PROCPS 3 "February 2021" "libproc-2"
|
2020-05-19 18:13:21 +05:30
|
|
|
.\" Please adjust this date whenever revising the manpage.
|
|
|
|
.\"
|
2020-06-20 10:30:00 +05:30
|
|
|
.nh
|
2020-05-19 18:13:21 +05:30
|
|
|
.SH NAME
|
2020-06-20 10:30:00 +05:30
|
|
|
procps \- API to access system level information in the /proc filesystem
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.SH SYNOPSIS
|
|
|
|
Five distinct interfaces are represented in this synopsis and named after
|
|
|
|
the files they access in the /proc pseudo filesystem:
|
|
|
|
.BR diskstats ", " meminfo ", " slabinfo ", " stat " and " vmstat .
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.nf
|
|
|
|
.RS +4
|
|
|
|
#include <procps/\fBnamed_interface\fR.h>
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.BI "int procps_new (struct info **" info );
|
|
|
|
.BI "int procps_ref (struct info *" info );
|
|
|
|
.BI "int procps_unref (struct info **" info );
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.BI "struct result *procps_get ("
|
|
|
|
.BI " struct info *" info ,
|
|
|
|
.RI "[ const char *" name ", ] \fBdiskstats\fR api only"
|
|
|
|
.BI " enum item " item );
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.BI "struct stack *procps_select ("
|
|
|
|
.BI " struct info *" info ,
|
|
|
|
.RI "[ const char *" name ", ] \fBdiskstats\fR api only"
|
|
|
|
.BI " enum item *" items ,
|
|
|
|
.BI " int " numitems );
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.BI "struct reaped *procps_reap ("
|
|
|
|
.BI " struct info *" info ,
|
|
|
|
.RI "[ enum reap_type " what ", ] \fBstat\fR api only"
|
|
|
|
.BI " enum item *" items ,
|
|
|
|
.BI " int " numitems );
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
.BI "struct stack **procps_sort ("
|
|
|
|
.BI " struct info *" info ,
|
|
|
|
.BI " struct stack *" stacks[] ,
|
|
|
|
.BI " int " numstacked ,
|
|
|
|
.BI " enum item " sortitem ,
|
|
|
|
.BI " enum sort_order " order );
|
|
|
|
.RE
|
|
|
|
.fi
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
The above functions and structures are generic but the specific
|
|
|
|
\fBnamed_interface\fR would also be part of any identifiers.
|
|
|
|
For example, `procps_new' would actually be `procps_\fBmeminfo\fR_new'
|
|
|
|
and `info' would really be `\fBdiskstats\fR_info', etc.
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
The same \fBnamed_interface\fR is used in each header file name with
|
|
|
|
an appended `.h' suffix.
|
2020-05-19 18:13:21 +05:30
|
|
|
|
2021-02-20 17:00:31 +05:30
|
|
|
Link with \fI\-lproc-2\fP.
|
2020-05-19 18:13:21 +05:30
|
|
|
|
|
|
|
.SH DESCRIPTION
|
2020-06-20 10:30:00 +05:30
|
|
|
.SS Overview
|
|
|
|
Central to these interfaces is a simple `result'
|
|
|
|
structure reflecting an `item' plus its value (in a union
|
|
|
|
with standard C language types as members).
|
|
|
|
All `result' structures are automatically allocated and
|
|
|
|
provided by the library.
|
|
|
|
|
|
|
|
By specifying an array of `items', these structures can be
|
|
|
|
organized as a `stack', potentially yielding many results
|
|
|
|
with a single function call.
|
|
|
|
Thus, a `stack' can be viewed as a variable length record
|
|
|
|
whose content and order is determined solely by the user.
|
|
|
|
|
2021-02-15 11:30:00 +05:30
|
|
|
As part of each interface there are two unique enumerators.
|
2020-06-20 10:30:00 +05:30
|
|
|
The `noop' and `extra' items exist to hold user values.
|
|
|
|
They are never set by the library, but the `extra'
|
|
|
|
result will be zeroed with each library interaction.
|
|
|
|
|
|
|
|
The \fBnamed_interface\fR header file will be an essential
|
|
|
|
document during user program development.
|
|
|
|
There you will find available items, their return type
|
|
|
|
(the `result' struct member name) and the source for such values.
|
|
|
|
Additional enumerators and structures are also documented there.
|
|
|
|
|
|
|
|
.SS Usage
|
|
|
|
The following would be a typical sequence of calls to
|
|
|
|
these interfaces.
|
|
|
|
|
|
|
|
.nf
|
|
|
|
.RB "1. " procps_new()
|
|
|
|
.RB "2. " procps_get() ", " procps_select() " or " procps_reap()
|
|
|
|
.RB "3. " procps_unref()
|
|
|
|
.fi
|
|
|
|
|
2021-02-15 11:30:00 +05:30
|
|
|
The \fBget\fR function is used to retrieve a `result' structure for
|
|
|
|
a single `item'.
|
|
|
|
Alternatively, a \fBGET\fR macro is available when only the return
|
|
|
|
value is of interest.
|
|
|
|
|
|
|
|
The \fBselect\fR function can retrieve multiple `result' structures
|
|
|
|
in a single `stack'.
|
|
|
|
|
|
|
|
For unpredictable variable outcomes, the \fBdiskstats\fR, \fBslabinfo\fR
|
|
|
|
and \fBstat\fR interfaces export a \fBreap\fR function.
|
|
|
|
It is used to retrieve multiple `stacks' each containing multiple
|
|
|
|
`result' structures.
|
|
|
|
Optionally, a user may choose to \fBsort\fR those results.
|
|
|
|
|
|
|
|
To exploit any `stack', and access individual `result' structures,
|
|
|
|
a \fIrelative_enum\fR is required as shown in the \fBVAL\fR macro
|
|
|
|
defined in the header file.
|
|
|
|
Such values could be hard coded as: 0 through numitems-1.
|
|
|
|
However, this need is typically satisfied by creating your own
|
|
|
|
enumerators corresponding to the order of the `items' array.
|
2020-06-20 10:30:00 +05:30
|
|
|
|
|
|
|
.SS Caveats
|
|
|
|
The \fBnew\fR, \fBref\fR, \fBunref\fR, \fBget\fR and \fBselect\fR
|
|
|
|
functions are available in all five interfaces.
|
|
|
|
|
|
|
|
For the \fBnew\fR and \fBunref\fR functions, the address of an \fIinfo\fR
|
|
|
|
struct pointer must be supplied.
|
|
|
|
With \fBnew\fR it must have been initialized to NULL.
|
|
|
|
With \fBunref\fR it will be reset to NULL if the reference count reaches zero.
|
|
|
|
|
|
|
|
In the case of the \fBdiskstats\fR interface, a \fIname\fR parameter
|
|
|
|
on the \fBget\fR and \fBselect\fR functions identifies a disk or
|
|
|
|
partition name
|
|
|
|
|
2021-02-15 11:30:00 +05:30
|
|
|
For the \fBstat\fR interface, a \fIwhat\fR parameter on the \fBreap\fR
|
|
|
|
function identifies whether data for just CPUs or both CPUs and NUMA
|
|
|
|
nodes is to be gathered.
|
|
|
|
|
|
|
|
When usng the \fBsort\fR function, the parameters \fIstacks\fR and
|
|
|
|
\fInumstacked\fR would normally be those returned in the `reaped'
|
|
|
|
structure.
|
2020-05-19 18:13:21 +05:30
|
|
|
|
|
|
|
.SH RETURN VALUE
|
2020-06-20 10:30:00 +05:30
|
|
|
.SS Functions Returning an `int'
|
|
|
|
An error will be indicated by a negative number that
|
|
|
|
is always the inverse of some well known errno.h value.
|
|
|
|
|
|
|
|
Success is indicated by a zero return value.
|
|
|
|
However, the \fBref\fR and \fBunref\fR functions return
|
|
|
|
the current \fIinfo\fR structure reference count.
|
|
|
|
|
|
|
|
.SS Functions Returning an `address'
|
|
|
|
An error will be indicated by a NULL return pointer
|
|
|
|
with the reason found in the formal errno value.
|
|
|
|
|
|
|
|
Success is indicated by a pointer to the named structure.
|
|
|
|
|
|
|
|
.SH DEBUGGING
|
|
|
|
To aid in program development, there is a provision that can
|
|
|
|
help ensure `result' member references agree with library
|
|
|
|
expectations.
|
2020-06-24 03:59:14 +05:30
|
|
|
It assumes that a supplied macro in the header file is
|
|
|
|
used to access the `result' value.
|
|
|
|
|
2020-06-20 10:30:00 +05:30
|
|
|
This feature can be activated through either of the following
|
|
|
|
methods and any discrepancies will be wrtten to \fBstderr\fR.
|
|
|
|
|
|
|
|
.IP 1) 3
|
|
|
|
Add CFLAGS='-DXTRA_PROCPS_DEBUG' to any other ./configure
|
|
|
|
options employed.
|
|
|
|
|
|
|
|
.IP 2) 3
|
|
|
|
Add #include <procps/xtra-procps-debug.h> to any program
|
|
|
|
\fIafter\fR the named interface includes.
|
|
|
|
|
2020-05-19 18:13:21 +05:30
|
|
|
.PP
|
2020-06-20 10:30:00 +05:30
|
|
|
This verification feature incurs substantial overhead.
|
|
|
|
Therefore, it is important that it \fInot\fR be activated
|
|
|
|
for a production/release build.
|
2020-05-19 18:13:21 +05:30
|
|
|
|
|
|
|
.SH SEE ALSO
|
2020-06-20 10:30:00 +05:30
|
|
|
.BR procps_misc (3)
|
|
|
|
.BR procps_pids (3)
|
|
|
|
.BR proc (5).
|