Using getrlimit(RLIMIT_MEMLOCK), one can get the allowed amount of locked memory a process can allocate (mlock() or mlockall()).

But how to retrieve the currently locked memory amount ?

For example, there's no information returned by getrusage().

Under Linux, it is possible to read /proc/self/status and extract the amount of locked memory from the line beginning with VmLck.

Is there a portable way to retrieve the amount of locked memory which would work on Linux, *BSD and other POSIX compatible systems ?

Edit
Report