MLOCK(3)                   POSIX Programmer's Manual                  MLOCK(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       mlock, munlock -- lock or unlock a range of process address space
       (RREEAALLTTIIMMEE)

SSYYNNOOPPSSIISS
       #include <sys/mman.h>

       int mlock(const void *_a_d_d_r, size_t _l_e_n);
       int munlock(const void *_a_d_d_r, size_t _l_e_n);

DDEESSCCRRIIPPTTIIOONN
       The _m_l_o_c_k() function shall cause those whole pages containing any part
       of the address space of the process starting at address _a_d_d_r and
       continuing for _l_e_n bytes to be memory-resident until unlocked or until
       the process exits or _e_x_e_cs another process image. The implementation
       may require that _a_d_d_r be a multiple of {PAGESIZE}.

       The _m_u_n_l_o_c_k() function shall unlock those whole pages containing any
       part of the address space of the process starting at address _a_d_d_r and
       continuing for _l_e_n bytes, regardless of how many times _m_l_o_c_k() has been
       called by the process for any of the pages in the specified range. The
       implementation may require that _a_d_d_r be a multiple of {PAGESIZE}.

       If any of the pages in the range specified to a call to _m_u_n_l_o_c_k() are
       also mapped into the address spaces of other processes, any locks
       established on those pages by another process are unaffected by the
       call of this process to _m_u_n_l_o_c_k().  If any of the pages in the range
       specified by a call to _m_u_n_l_o_c_k() are also mapped into other portions of
       the address space of the calling process outside the range specified,
       any locks established on those pages via the other mappings are also
       unaffected by this call.

       Upon successful return from _m_l_o_c_k(), pages in the specified range shall
       be locked and memory-resident. Upon successful return from _m_u_n_l_o_c_k(),
       pages in the specified range shall be unlocked with respect to the
       address space of the process. Memory residency of unlocked pages is
       unspecified.

       Appropriate privileges are required to lock process memory with
       _m_l_o_c_k().

RREETTUURRNN VVAALLUUEE
       Upon successful completion, the _m_l_o_c_k() and _m_u_n_l_o_c_k() functions shall
       return a value of zero. Otherwise, no change is made to any locks in
       the address space of the process, and the function shall return a value
       of -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _m_l_o_c_k() and _m_u_n_l_o_c_k() functions shall fail if:

       EENNOOMMEEMM Some or all of the address range specified by the _a_d_d_r and _l_e_n
              arguments does not correspond to valid mapped pages in the
              address space of the process.

       The _m_l_o_c_k() function shall fail if:

       EEAAGGAAIINN Some or all of the memory identified by the operation could not
              be locked when the call was made.

       The _m_l_o_c_k() and _m_u_n_l_o_c_k() functions may fail if:

       EEIINNVVAALL The _a_d_d_r argument is not a multiple of {PAGESIZE}.

       The _m_l_o_c_k() function may fail if:

       EENNOOMMEEMM Locking the pages mapped by the specified range would exceed an
              implementation-defined limit on the amount of memory that the
              process may lock.

       EEPPEERRMM  The calling process does not have appropriate privileges to
              perform the requested operation.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _e_x_e_c, _e_x_i_t(), _f_o_r_k(), _m_l_o_c_k_a_l_l(), _m_u_n_m_a_p()

       The Base Definitions volume of POSIX.1-2008, <<ssyyss__mmmmaann..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                             MLOCK(3)
