PROCPS_MISC(3)

πŸ’– PROCPS_MISC(3) β€” the procps_misc era πŸ’–

okay bestie, sit down, hydrate, because today we're learning procps_misc β€” the part of the procps-ng library functions manual that handles all the miscellaneous lil facts living in the /proc filesystem. she's giving ✨utility✨, she's giving 🌸supporting cast🌸, and honestly? she ate.


🌈 NAME 🌈

procps_misc</purl> β€” the API for miscellaneous information in the /proc filesystem 🫢


✨ SYNOPSIS ✨

#include <libproc2/misc.h>

πŸŽ€ Platform Particulars πŸŽ€

long         procps_cpu_count (void);
long         procps_hertz_get (void);
unsigned int procps_pid_length (void);
int          procps_linux_version (void);

πŸ¦‹ Runtime Particulars πŸ¦‹

int   procps_container_uptime (double *uptime_secs);
int   procps_loadavg (double *av1, double *av5, double *av15);
int   procps_uptime (double *uptime_secs, double *idle_secs);
int   procps_uptime_snprint ( char *restrict str, size_t size, double uptime_secs, const int pretty);
char *procps_uptime_sprint (void);
char *procps_uptime_sprint_short (void);
int   procps_users (void);

🌸 Namespace Particulars 🌸

int         procps_ns_get_id (const char *name);
const char *procps_ns_get_name (int id);
int         procps_ns_read_pid (int pid, struct procps_ns *nsp);

πŸ’… Mask Name Resolving πŸ’…

int procps_sigmask_names (char *const str, size_t size , const char *sigmask);
int procps_capmask_names (char *const str, size_t size,  const char *capmask);

and like, obviously you link with -lproc2. don't forget her. she's the whole point. 😭


πŸ’œ DESCRIPTION πŸ’œ

procps_cpu_count() returns the number of CPUs that are currently online as sysconf(_SC_NPROCESSORS_ONLY) or an assumed 1. if the system's being mysterious about it, we just assume 1. iconic behavior honestly.

procps_hertz_get() returns the number of clock ticks per second as sysconf(_SC_CLK_TCK) or an assumed 100. and listen β€” dividing tics by this value yields seconds. that's the whole trick, no cap. ⏱️

procps_pid_length() returns the maximum string length for a PID on the system. like, for example, if the largest possible PID value on was 123, then the length would be 3. and if the file /proc/sys/kernel/pid_max is unreadable? the value is assumed to be 5. we move. πŸ™ˆ

procps_linux_version() returns the current Linux version as an encoded integer. on non-Linux systems that have an emulated proc filesystem this function returns the version of the Linux emulation instead β€” so it's cosplaying, respectfully. the version consists of three positive integers representing the major, minor and patch levels. and the following macros are provided for encoding a given Linux version or separating out the components of the current version:

LINUX_VERSION( major , minor , patch )

LINUX_VERSION_MAJOR( ver )

LINUX_VERSION_MINOR( ver )

LINUX_VERSION_PATCH( ver )

procps_loadavg() fetches the system load average and puts the 1, 5 and 15 minute averages into location(s) specified by any pointer which is not NULL. if you pass NULL, she simply does not fill it. boundaries! 🫢

procps_container_uptime() returns the uptime of a container into location specified by the pointer if it is not NULL. this is currently determined by the elapsed time of PID 1, which could be given with the command:

$ ps -o etimes 1
ELAPSED
12345
πŸ’€ there is no concept of idle time in a container so procps_container_uptime() doesn't have that parameter. she literally cannot give you what doesn't exist, bestie.

procps_uptime() returns uptime and/or idle seconds into location(s) specified by any pointer which is not NULL. the sprint varieties return a human-readable string in one of two forms. ✨

HH:MM:SS up HH:MM, # users, load average: 1, 5, 15 MM averages

up HH, MM

procps_uptime_snprint() Uses the given buffer str of size length to fill in the uptime string instead of a statically allocated buffer. the function requires the uptime_secs value, which can be obtained from procps_uptime() or procps_container_uptime() and the pretty flag determines if the output is standard or pretty/short. choose your aesthetic πŸŽ€

procps_users() returns the number of users on the system. this value comes from sd_get_sessions(3) and counting the sessions of user, user-early and user-incomplete class or enumerating through getutent(3). two paths, same truth. 🌈

procps_ns_get_id() returns the integer id (enum namespace_type) of the namespace for the given namespace name.

procps_ns_get_name() returns the name of the namespace for the given id (enum namespace_type).

procps_ns_read_pid() returns the inodes for the namespaces of the given process in the procps_ns structure pointed to by nsp. those inodes will appear in the order proscribed by enum namespace_type. πŸ‘‘

enum namespace_type {
    PROCPS_NS_CGROUP,
    PROCPS_NS_IPC,
    PROCPS_NS_MNT,
    PROCPS_NS_NET,
    PROCPS_NS_PID,
    PROCPS_NS_TIME,
    PROCPS_NS_USER,
    PROCPS_NS_UTS
};

procps_sigmask_names() Fills str with a human-readable text string of up to size bytes of the signals set in the hexadecimal signal mask sigmask, see signal(7). If the list of signals exceeds size bytes, the string will be truncated and will end with a '+'. It is up to the calling program to ensure that str is correctly allocated with at least size bytes. yes, you have to allocate it. she is not your mom. 😌

procps_capmask_names() Fills str with a human-readable text string of up to size bytes of the capabilities set in the hexadecimal capability mask capmask, see capabilities(7). If the list of capabilities exceeds size bytes, the string will be truncated and will end with a '+'. It is up to the calling program to ensure that str is correctly allocated with at least size bytes. same energy, different mask. πŸ’…

For a process that has no capabilities or all capabilities the string will be "-" and "full" respectively. nothing / everything. the duality of process. πŸ¦‹


πŸ”₯ RETURN VALUE πŸ”₯

πŸ’– Functions Returning an β€˜int’ or β€˜long’ πŸ’–

An error will be indicated by a negative number that is always the inverse of some well known errno.h value. so like, negative = bad news, flip it and you got your errno. slay, but make it tragic.

πŸ’– Functions Returning an β€˜address’ πŸ’–

An error will be indicated by a NULL return pointer with the reason found in the formal errno value. NULL said "not today" and errno will tell you why. πŸ’€


🌸 FILES 🌸

  • /proc/loadavg β€” The raw values for load average.
  • /proc/sys/kernel/osrelease β€” Contains the release version of the Linux kernel or proc filesystem.
  • /proc/sys/kernel/pid_max β€” Contains the value at which PIDs wrap around, one greater than the maximum PID value.
  • /proc/uptime β€” The raw values for system uptime and idle time.
  • /proc/PID/ns β€” contains the set of namespaces for a particular PID.

🫢 SEE ALSO 🫢

procps(3), procps_pids(3), getutent(3), sd_get_sessions(3), proc(5), capabilities(7), signal(7).


and that's the whole page, bestie, no skips, no skimming, every flag and file accounted for ✨ this one came from procps-ng, dated 2024-07-06, and she is literally iconic. go forth and read your /proc πŸ’–πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from