mlock()

Lock a range of process address space in physical memory

Synopsis:

#include <sys/mman.h>

int mlock(const void * addr, 
          size_t len);

Arguments:

addr
The starting address for the range of process address space.
len
The amount of the memory to lock, in bytes. There's no limit on the amount of memory that a process may lock, other than the amount of physical memory in the system.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The mlock() function locks a range of process address space starting at address addr and continuing for length len. The addr must be a multiple of PAGESIZE, which depends on the target platform.


Note: The full POSIX implementation for this function was added in the QNX Neutrino Core OS 6.3.2.

The calling process needs superuser capabilities to call mlock().


The successful call to mlock() function ensures that the pages are memory-resident (i.e. the addresses always reside in physical memory). For more information, see Locking memory in the Process Manager chapter of the System Architecture guide.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

ENOMEM
EAGAIN
Some or all of the memory identified by the operation couldn't be locked when the call was made.
EPERM
The calling process doesn't have the superuser capabilities.

Classification:

POSIX 1003.1 MLR

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

mlockall(), mmap(), munlock(), munlockall()

Locking memory in the Process Manager chapter of the System Architecture guide