PGET(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ‘‘ PGET(9) β€” the Kernel Developer's Manual, bestie edition ✨

okay so real talk, this one's from the kernel dev manual and it's literally called pget β€” the whole vibe is "find a process by number" πŸ’…


🌸 NAME

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


✨ SYNOPSIS

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

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

πŸ’– DESCRIPTION

okay so here's the tea β˜• β€” this function takes a pid as its argument, and that pid can be either a process id or a thread id, and it fills a pointer to the proc structure into *pp. in the thread-id case, it goes looking for the process that owns the specified thread. the actual searching is done by calling pfind(9). iconic delegation honestly 🫢

now the important part, don't skip this πŸ‘‡ the found process is returned locked. except for the PGET_HOLD case, where it comes back unlocked (but held). and depending on the flags argument, pget() can do some extra little manipulations on top of that. main character energy 🌟

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

  • PGET_HOLD β€” if set, the found process will be held and unlocked πŸ’œ
  • PGET_CANSEE β€” if set, the found process gets checked for its visibility. see p_cansee(9) πŸ‘€
  • PGET_CANDEBUG β€” if set, the found process gets checked for its debuggability. see p_candebug(9) πŸ›
  • PGET_ISCURRENT β€” if set, the found process gets checked that it matches the current process context 🎯
  • 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 a shorthand for (PGET_HOLD | PGET_CANDEBUG | PGET_NOTWEXIT) ✨

πŸ”₯ RETURN VALUES

if the process is found in the specified way, you get zero back β€” slay πŸŽ‰ otherwise you get an appropriate error code. no cap, that's the whole contract πŸ’€


πŸ¦‹ SEE ALSO

p_candebug(9), p_cansee(9), pfind(9) β€” go read these too, iykyk πŸ’–


and that's the page!! πŸŽ€ this little gem is from the Debian edition of the manual, dated May 3, 2014 β€” oldie but a goodie, and it still ate πŸ’…βœ¨

πŸ“¦ where this page comes from