int mlock (
const void *addr,
int munlock (
const void *addr,
The mlock and munlock functions lock and unlock whole pages containing any part of the process address space starting at addr and continuing for len bytes.
The mlock function guarantees all whole pages mapped by the range addr to addr+len-1 (inclusive) to be memory resident. (The area locked is the same as if the len argument were rounded up to a multiple of the page size before decrementing by 1.)
The locked area remains locked until unlocked with a call to the munlock function, the process calls the exec function, an address space associated with the lock is unmapped, or the process terminates. A lock is not inherited across a fork or an exec.
The munlock function unlocks whole pages previously mapped by the range addr to addr+len-1 (inclusive), regardless of how many times the mlock function was called by the process for any pages within the specified range.
A call to the munlock function does not affect pages that may be mapped into another process's address space or locked by another process.
You must have superuser privileges to call the mlock or munlock functions.
On a successful call to the mlock function, a value of 0 is returned and the region becomes locked and memory resident. On an unsuccessful call, a value of -1 is returned, no changes are made to any locks in the process address space, and errno is set to indicate that an error occurred.
On a successful call to the munlock function, a value of 0 is returned and the memory is unlocked with respect to the process's address space. On an unsuccessful call, a value of -1 is returned, none of the memory is unlocked, and errno is set to indicate that an error occurred.
The mlock and munlock functions fail under the following conditions:
If any of the following conditions occur, the mlock function shall fail:
Functions: exec(2), _exit(2), fork(2), munmap(2), sysconf(3) delim off