OPENPROC(3)

πŸ“¦ version 3.3.17, in centos-stream 9, ubuntu jammy

πŸ‘‘ OPENPROC(3) πŸ‘‘ β€” openproc, closeproc

okay bestie, welcome to the Linux Programmer's Manual page for openproc and closeproc. this is the one that gets your process info from /proc/. sit down, hydrate, we're doing this πŸ’…


✨ NAME ✨

openproc, closeproc β€” initialize process information from /proc/ 🫢


🌸 SYNOPSIS 🌸

#include <proc/readproc.h>

PROCTAB* openproc (int flags, ... );
void closeproc (PROCTAB* PT);

🌸 SYNOPSIS 🌸 (yes it's here twice, the manpage said so, i don't make the rules 😭)

so openproc is the girl who sets up your PROCTAB structure. once it's initialized, you can hit it with iterated readproc calls to get all the tea on the current processes. depending on what flags you pass, openproc might need a second argument, or a second and third argument (more on that below πŸ‘‡).

closeproc is the responsible bestie: it closes all files opened by openproc and deallocates all the memory openproc allocated. no leaks, we don't do that here ✨

and btw, the PROCTAB structure is defined in <proc/readproc.h> πŸ’–


πŸ¦‹ RETURN VALUE πŸ¦‹

openproc hands you back a pointer to a PROCTAB structure β€” slay β€” or NULL if something goes wrong. and ngl, NULL usually means the process can't read /proc. not iconic. 😭


πŸ’… FLAGS πŸ’…

the whole personality of openproc is controlled by this flag set, and you can OR them together. there are three different kinds of flags, bestie, keep up:

  1. group one decides which information gets read from /proc/#pid for each process.
  2. group two narrows down which processes get their info read, by giving it a list of criteria β€” and heads up, only one of these can be enacted for an opendir call.
  3. group three also restricts stuff, but doesn't need arguments. these can be used together again πŸŽ€

now the flags themselves, one by one, no skipping, periodt:

  • PROC_FILLMEM β€” read information from /proc/#pid/statm
  • PROC_FILLCOM β€” allocate the cmdline part of proc_t and read information from /proc/#pid/cmdline
  • PROC_FILLENV β€” allocate the environ part of proc_t and read information from /proc/#pid/environ
  • PROC_FILLUSR β€” resolve user ids to names via /etc/passwd
  • PROC_FILLGRP β€” resolve group ids to names via /etc/group
  • PROC_FILLSTATUS β€” read information from /proc/#pid/status
  • PROC_FILLSTAT β€” read information from /proc/#pid/stat
  • PROC_FILLARG β€” equivalent to PROC_FILLCOM
  • PROC_FILLCGROUP β€” alloc and fill in cgroup
  • PROC_FILLSUPGRP β€” resolve supplementary group id -> group name
  • PROC_FILLOOM β€” fill in proc_t oom_score and oom_adj
  • PROC_FILLNS β€” fill in proc_t namespace information
  • PROC_FILLSYSTEMD β€” fill in proc_t systemd information
  • PROC_LOOSE_TASKS β€” treats threads as if they were processes (yes really, threads get main character treatment πŸ‘‘)
  • PROC_PID (2nd argument pid_t* pidlist) β€” lookup only processes whose pid is contained in pidlist (the list is terminated with 0)
  • PROC_UID (arguments uid_t* uidlist, int n) β€” lookup only processes whose user id is contained in uidlist (where n is the number of uids contained in the list)
  • PROC_EDITCGRPCVT β€” edit cgroup as single vector
  • PROC_EDITCMDLCVT β€” edit cmdline as single vector
  • PROC_EDITENVRCVT β€” edit environ as single vector

πŸ™ˆ NOTE πŸ™ˆ

bestie listen. only one of the flags that need extra arguments β€” that's PROC_{PID,UID} β€” may be used at a time. one. not two. i'm serious. 🫠

🌈 SEE ALSO 🌈


πŸ’€ REPORTING BUGS πŸ’€

found a bug? please send bug reports to procps@freelists.org β€” they want to hear from you fr fr 🫢


this has been a page from the Linux Manpage, dated 14 July 2014, titled OPENPROC(3) β€” and that's the whole vibe check. bye bestie, go close your file descriptors πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from