KINFO_GETALLPROC(3)

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

πŸ’– NAME πŸ’–

okay bestie, meet kinfo_getallproc(3) β€” the function for getting process information for, like, all the processes from the kernel. no cap, it's the full roster. πŸ‘‘

πŸ“š LIBRARY πŸ“š

System Utilities Library β€” that's libutil, link it with -lutil. πŸ’…

✨ SYNOPSIS ✨

#include <sys/types.h>
#include <sys/user.h>
#include <libutil.h>

struct kinfo_proc *
kinfo_getallproc(int *cntp);

🫢 DESCRIPTION 🫢

So this function is literally used for obtaining process information of all processes from the kernel. every single one. main character energy for the whole process table. πŸ¦‹

The cntp field is a pointer containing the number of process structures returned. it's giving "here's how many came back". ✨

It's a wrapper around sysctl(3) with the KERN_PROC_PROC mib. While the kernel returns a packed structure, this function expands the data into a fixed record format. yes, it's doing the glow-up from packed to fixed records. πŸ’…

πŸŽ€ RETURN VALUES πŸŽ€

On success, the kinfo_getallproc() function returns a pointer to cntp struct kinfo_proc structures as defined by <sys/user.h>. 🫢

That pointer was obtained by an internal call to malloc(3) and must be freed by the caller with a call to free(3). bestie, do not forget the free(3) β€” that's the whole vibe check. 😭

On failure, the kinfo_getallproc() function returns NULL. and that's it. πŸ’€

πŸ‘€ SEE ALSO πŸ‘€

🌈 HISTORY 🌈

The kinfo_getallproc() function first appeared in FreeBSD 8.3. iconic behavior, honestly. πŸ‘‘


πŸ’Œ cute little source/version + date sign-off: this page is from Debian, dated May 8, 2020 β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from