| 1 |
.\" |
| 2 |
.\" Copyright (c) 2020-2024 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_MISC 3 2024-07-06 procps-ng |
| 12 |
.\" Please adjust this date whenever revising the manpage. |
| 13 |
.\" |
| 14 |
.nh |
| 15 |
.SH NAME |
| 16 |
procps_misc \- API for miscellaneous information in the /proc filesystem |
| 17 |
.SH SYNOPSIS |
| 18 |
.nf |
| 19 |
.B #include <libproc2/misc.h> |
| 20 |
.PP |
| 21 |
Platform Particulars |
| 22 |
.RS 4 |
| 23 |
.PP |
| 24 |
.RB "long " procps_cpu_count " (void); |
| 25 |
.RB "long " procps_hertz_get " (void); |
| 26 |
.RB "unsigned int " procps_pid_length " (void); |
| 27 |
.RB "int " procps_linux_version " (void); |
| 28 |
.RE |
| 29 |
.PP |
| 30 |
Runtime Particulars |
| 31 |
.PP |
| 32 |
.RS 4 |
| 33 |
.RI "int \fB procps_container_uptime\fR (double *" uptime_secs ");" |
| 34 |
.RI "int \fB procps_loadavg\fR (double *" av1 ", double *" av5 ", double *" av15 ");" |
| 35 |
.RI "int \fB procps_uptime\fR (double *" uptime_secs ", double *" idle_secs ");" |
| 36 |
.RI "int \fB procps_uptime_snprint\fR ( char *restrict " str ", size_t " size ", double " uptime_secs ", const int " pretty ");" |
| 37 |
.RB "char *" procps_uptime_sprint " (void);" |
| 38 |
.RB "char *" procps_uptime_sprint_short " (void);" |
| 39 |
.RB "int " procps_users " (void);" |
| 40 |
.RE |
| 41 |
.PP |
| 42 |
Namespace Particulars |
| 43 |
.PP |
| 44 |
.RS 4 |
| 45 |
.RI "int \fB procps_ns_get_id\fR (const char *" name ");" |
| 46 |
.RI "const char\fB *procps_ns_get_name\fR (int " id ");" |
| 47 |
.RI "int \fB procps_ns_read_pid\fR (int " pid ", struct procps_ns *" nsp ");" |
| 48 |
.RE |
| 49 |
.PP |
| 50 |
Mask Name Resolving |
| 51 |
.PP |
| 52 |
.RS 4 |
| 53 |
.RI "int \fBprocps_sigmask_names\fR (char *const " str ", size_t " size " , const char *" sigmask ");" |
| 54 |
.RI "int \fBprocps_capmask_names\fR (char *const " str ", size_t " size ", const char *" capmask ");" |
| 55 |
.RE |
| 56 |
.PP |
| 57 |
.P |
| 58 |
Link with \fI\-lproc2\fP. |
| 59 |
.SH DESCRIPTION |
| 60 |
.BR procps_cpu_count () |
| 61 |
returns the number of CPUs that are currently online as |
| 62 |
.BI sysconf( _SC_NPROCESSORS_ONLY ) |
| 63 |
or an assumed \fI1\fR. |
| 64 |
.P |
| 65 |
.BR procps_hertz_get () |
| 66 |
returns the number of clock ticks per second as |
| 67 |
.BI sysconf( _SC_CLK_TCK ) |
| 68 |
or an assumed \fI100\fR. |
| 69 |
Dividing tics by this value yields seconds. |
| 70 |
.P |
| 71 |
.BR procps_pid_length () |
| 72 |
returns the maximum string length for a PID on the system. For example, if the largest |
| 73 |
possible PID value on was 123, then the length would be 3. If the file |
| 74 |
\fI/proc/sys/kernel/pid_max\fR is unreadable, the value is assumed to be \fI5\fR. |
| 75 |
.P |
| 76 |
.BR procps_linux_version () |
| 77 |
returns the current Linux version as an encoded integer. On non-Linux systems that |
| 78 |
have an emulated proc filesystem this function returns the version of the |
| 79 |
Linux emulation instead. |
| 80 |
The version consists of three positive integers representing the major, |
| 81 |
minor and patch levels. |
| 82 |
The following macros are provided for encoding a given Linux version or |
| 83 |
separating out the components of the current version. |
| 84 |
.RS 4 |
| 85 |
.PP |
| 86 |
LINUX_VERSION(\ major\ ,\ minor\ ,\ patch\ ) |
| 87 |
.PP |
| 88 |
LINUX_VERSION_MAJOR(\ ver\ ) |
| 89 |
.PP |
| 90 |
LINUX_VERSION_MINOR(\ ver\ ) |
| 91 |
.PP |
| 92 |
LINUX_VERSION_PATCH(\ ver\ ) |
| 93 |
.RE |
| 94 |
.P |
| 95 |
.BR procps_loadavg () |
| 96 |
fetches the system load average and puts the 1, 5 and 15 minute averages into |
| 97 |
location(s) specified by any pointer which is not \fINULL\fR. |
| 98 |
.P |
| 99 |
.BR procps_container_uptime () |
| 100 |
returns the uptime of a container into location specified by the pointer |
| 101 |
if it is not \fINULL\fR. This is currently determined by the elapsed time of PID 1, |
| 102 |
which could be given with the command: |
| 103 |
.PP |
| 104 |
.in +4n |
| 105 |
.EX |
| 106 |
$ \fBps -o etimes 1\fR |
| 107 |
ELAPSED |
| 108 |
12345 |
| 109 |
.EE |
| 110 |
.in |
| 111 |
.PP |
| 112 |
There is no concept of idle time in a container so \fBprocps_container_uptime\fR() |
| 113 |
doesn't have that parameter. |
| 114 |
.P |
| 115 |
.BR procps_uptime () |
| 116 |
returns uptime and/or idle seconds into location(s) specified by any pointer |
| 117 |
which is not \fINULL\fR. |
| 118 |
The \fBsprint\fR varieties return a human-readable string in one of two forms. |
| 119 |
.RS 4 |
| 120 |
.PP |
| 121 |
HH:MM:SS up HH:MM, # users, load average: 1, 5, 15 MM averages |
| 122 |
.PP |
| 123 |
up HH, MM |
| 124 |
.RE |
| 125 |
.P |
| 126 |
.BR procps_uptime_snprint () |
| 127 |
Uses the given buffer \fIstr\fR of \fIsize\fR length to fill in the uptime string |
| 128 |
instead of a statically allocated buffer. |
| 129 |
The function requires the \fIuptime_secs\fR value, which can be obtained from |
| 130 |
.BR procps_uptime () |
| 131 |
or |
| 132 |
.BR procps_container_uptime () |
| 133 |
and the \fIpretty\fR flag determines if the output is standard or pretty/short. |
| 134 |
.P |
| 135 |
.BR procps_users () |
| 136 |
returns the number of users on the system. This value comes from |
| 137 |
.BR sd_get_sessions (3) |
| 138 |
and counting the sessions of user, user-early and user-incomplete class |
| 139 |
or enumerating through |
| 140 |
.BR getutent (3). |
| 141 |
.P |
| 142 |
.BR procps_ns_get_id () |
| 143 |
returns the integer id (enum namespace_type) of the namespace for the given namespace \fIname\fR. |
| 144 |
.P |
| 145 |
.BR procps_ns_get_name () |
| 146 |
returns the name of the namespace for the given \fIid\fR (enum namespace_type). |
| 147 |
.P |
| 148 |
.BR procps_ns_read_pid () |
| 149 |
returns the inodes for the namespaces of the given process in the |
| 150 |
procps_ns structure pointed to by \fInsp\fR. |
| 151 |
Those inodes will appear in the order proscribed by enum namespace_type. |
| 152 |
.PP |
| 153 |
.RS 4 |
| 154 |
.nf |
| 155 |
enum namespace_type { |
| 156 |
PROCPS_NS_CGROUP, |
| 157 |
PROCPS_NS_IPC, |
| 158 |
PROCPS_NS_MNT, |
| 159 |
PROCPS_NS_NET, |
| 160 |
PROCPS_NS_PID, |
| 161 |
PROCPS_NS_TIME, |
| 162 |
PROCPS_NS_USER, |
| 163 |
PROCPS_NS_UTS |
| 164 |
}; |
| 165 |
.fi |
| 166 |
.RE |
| 167 |
.P |
| 168 |
.BR procps_sigmask_names () |
| 169 |
Fills \fIstr\fR with a human-readable text string of up to \fIsize\fR |
| 170 |
bytes of the signals set in the hexadecimal signal mask \fIsigmask\fR, |
| 171 |
see |
| 172 |
.BR signal (7). |
| 173 |
If the list of signals exceeds \fIsize\fR bytes, the string will be truncated and |
| 174 |
will end with a '+'. It is up to the calling program to ensure that \fIstr\fR |
| 175 |
is correctly allocated with at least \fIsize\fR bytes. |
| 176 |
.P |
| 177 |
.BR procps_capmask_names () |
| 178 |
Fills \fIstr\fR with a human-readable text string of up to \fIsize\fR |
| 179 |
bytes of the capabilities set in the hexadecimal capability mask \fIcapmask\fR, |
| 180 |
see |
| 181 |
.BR capabilities (7). |
| 182 |
If the list of capabilities exceeds \fIsize\fR bytes, the string will be truncated and |
| 183 |
will end with a '+'. It is up to the calling program to ensure that \fIstr\fR |
| 184 |
is correctly allocated with at least \fIsize\fR bytes. |
| 185 |
.P |
| 186 |
For a process that has no capabilities or all capabilities the string will be |
| 187 |
"-" and "full" respectively. |
| 188 |
|
| 189 |
.SH RETURN VALUE |
| 190 |
.SS Functions Returning an \[oq]int\[cq] or \[oq]long\[cq] |
| 191 |
An error will be indicated by a negative number that |
| 192 |
is always the inverse of some well known errno.h value. |
| 193 |
.SS Functions Returning an \[oq]address\[cq] |
| 194 |
An error will be indicated by a NULL return pointer |
| 195 |
with the reason found in the formal errno value. |
| 196 |
.SH FILES |
| 197 |
.TP |
| 198 |
.I /proc/loadavg |
| 199 |
The raw values for load average. |
| 200 |
.TP |
| 201 |
.I /proc/sys/kernel/osrelease |
| 202 |
Contains the release version of the Linux kernel or proc filesystem. |
| 203 |
.TP |
| 204 |
.I /proc/sys/kernel/pid_max |
| 205 |
Contains the value at which PIDs wrap around, one greater than the maximum PID value. |
| 206 |
.TP |
| 207 |
.I /proc/uptime |
| 208 |
The raw values for system uptime and idle time. |
| 209 |
.TP |
| 210 |
.IR /proc/ PID /ns |
| 211 |
contains the set of namespaces for a particular |
| 212 |
.IR PID . |
| 213 |
.SH SEE ALSO |
| 214 |
.BR procps (3), |
| 215 |
.BR procps_pids (3), |
| 216 |
.BR getutent (3), |
| 217 |
.BR sd_get_sessions (3), |
| 218 |
.BR proc (5), |
| 219 |
.BR capabilities (7), |
| 220 |
.BR signal (7). |