How much memory locked in a process How much memory locked in a process unix unix

How much memory locked in a process


You will probably need to check for each system and implement it accordingly. On Linux:

cat /proc/$PID/status | grep VmLck

You will probably need to do the same in C (read /proc line by line and search for VmLck), as this information is created in the function task_mem (in array.c) which I don't think you can access directly. Something like:

#include <unistd.h>#include <stdlib.h>#include <stdio.h>char cwd[PATH_MAX];sprintf(cwd, "/proc/%d/status", getpid());FILE* fp = fopen(cwd, "r");if(!fp) {    exit(EXIT_FAILURE);}while((read = getline(&line, &len, fp)) != -1) {    // search for line starting by "VmLck"}