PGET(9)

πŸ’… PGET β€” locate a process by number πŸ’…

okay bestie, welcome to pget(9), straight out of the Kernel Developer's Manual (yes we read kernel docs for fun now, it's a whole personality) ✨


πŸŽ€ NAME πŸŽ€

pget β€” find a process by its number, fr fr πŸ”


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/proc.h>

int
pget(pid_t pid, int flags, struct proc **pp);

like, that's the whole vibe. three args, one pointer-to-pointer, zero chill 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the way this works is: you hand pget() a pid, and that pid can be either a process id or a thread id β€” it's flexible like that πŸ’β€β™€οΈ β€” and then it fills in a pointer to the proc structure into *pp. and if you gave it a thread id? no worries, it goes looking for the process that owns that thread. queen behavior πŸ‘‘

the actual finding is done by calling the pfind(9) function, iykyk.

now here's the part you gotta remember, bestie: the found process comes back LOCKED. πŸ”’ but if you passed PGET_HOLD, it comes back unlocked instead (but held β€” which is a whole different thing, don't mix them up 😭).

and depending on what you put in flags, pget() will do extra little manipulations on top. it's giving ✨customizable✨.

the flags argument is the logical OR of some subset of these:

  • PGET_HOLD β€” if set, the found process gets held and unlocked. (the opposite-lock vibe, we love her 🌸)
  • PGET_CANSEE β€” if set, the found process gets its visibility checked. see p_cansee(9) πŸ‘€
  • PGET_CANDEBUG β€” if set, the found process gets checked for debuggability. see p_candebug(9) πŸ›
  • PGET_ISCURRENT β€” if set, the found process gets checked that it matches the current process context. "is it me? am I the drama?" πŸͺž
  • PGET_NOTWEXIT β€” if set, the found process gets checked that it does not have the process flag P_WEXIT set. πŸšͺ
  • PGET_NOTINEXEC β€” if set, the found process gets checked that it does not have the process flag P_INEXEC set. πŸƒβ€β™€οΈ
  • PGET_NOTID β€” if set, pid is not assumed as a thread id for values larger than PID_MAX. πŸ”’
  • PGET_WANTREAD β€” if set, the found process gets checked that the caller may get read access to its structure. it's literally a shorthand for (PGET_HOLD | PGET_CANDEBUG | PGET_NOTWEXIT) πŸ’–

🌈 RETURN VALUES 🌈

if the process is found in the specified way β†’ zero gets returned, slay ✨

otherwise β†’ an appropriate error code comes back instead. not slay πŸ’€


πŸ‘‘ SEE ALSO πŸ‘‘

p_candebug(9), p_cansee(9), pfind(9) β€” go read your siblings, they're iconic too 🫢


and that's the whole page, bestie πŸ’œ this one's from Debian, dated May 3, 2014 β€” vintage, honestly. go lock a process responsibly, mwah πŸ˜˜πŸ’…

πŸ“¦ where this page comes from