KINFO_GETVMMAP(3)

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

🌸 NAME 🌸

okay bestie, welcome to KINFO_GETVMMAP(3) from the Library Functions Manual β€” this is all about kinfo_getvmmap, the function for getting per-process memory map information. πŸ’…βœ¨


🫢 LIBRARY 🫢

System Utilities Library (libutil, -lutil) β€” that’s the vibe. πŸŽ€


✨ SYNOPSIS ✨

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

struct kinfo_vmentry *
kinfo_getvmmap(pid_t pid, int *cntp);

πŸ’– DESCRIPTION πŸ’–

So this function is your go-to for obtaining virtual memory mapping information of a particular process. πŸ‘‘

The pid field contains the process identifier. It should be a process that you have privilege to access β€” no sneaky peeking at stuff you’re not allowed to see, bestie. πŸ™ˆ

The cntp field is how the caller gets to know how many records are returned. Very demure, very useful. πŸŽ€

This function is a wrapper around sysctl(3) with the KERN_PROC_VMMAP mib. The kernel returns a packed structure, but this function expands the data into a fixed record format. Slay. ✨


πŸ¦‹ RETURN VALUES πŸ¦‹

On success, kinfo_getvmmap() returns a pointer to an array of struct kinfo_vmentry structures as defined by <sys/user.h>. That array was obtained by an internal call to malloc(3) and must be freed by the caller with a call to free(3). Don’t leave it hanging, bestie. 😭

On failure, kinfo_getvmmap() returns NULL. πŸ’€


πŸ”₯ SEE ALSO πŸ”₯


🌈 HISTORY 🌈

The kinfo_getvmmap() function first appeared in FreeBSD 7.0. iconic behavior. πŸ‘‘


πŸ’œ CAVEATS πŸ’œ

ngl, this one matters: kinfo_getvmmap() calls can cause significant CPU consumption because calculating the residency counts requires iterating over all memory pages of the process. 😭

Setting the sysctl variable kern.proc_vmmap_skip_resident_count to 1 prevents this calculation. Consider that your built-in low-power mode. πŸ”‹βœ¨


mwah πŸ’‹ β€” this page is from Debian, dated May 10, 2020. πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from