1MLOCK(3P)                  POSIX Programmer's Manual                 MLOCK(3P)
2
3
4

PROLOG

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

NAME

12       mlock, munlock — lock or unlock a range of process address space (REAL‐
13       TIME)
14

SYNOPSIS

16       #include <sys/mman.h>
17
18       int mlock(const void *addr, size_t len);
19       int munlock(const void *addr, size_t len);
20

DESCRIPTION

22       The  mlock() function shall cause those whole pages containing any part
23       of the address space of the process starting at address addr  and  con‐
24       tinuing for len bytes to be memory-resident until unlocked or until the
25       process exits or execs another process image.  The  implementation  may
26       require that addr be a multiple of {PAGESIZE}.
27
28       The  munlock()  function  shall unlock those whole pages containing any
29       part of the address space of the process starting at address  addr  and
30       continuing for len bytes, regardless of how many times mlock() has been
31       called by the process for any of the pages in the specified range.  The
32       implementation may require that addr be a multiple of {PAGESIZE}.
33
34       If  any  of the pages in the range specified to a call to munlock() are
35       also mapped into the address  spaces  of  other  processes,  any  locks
36       established  on  those  pages  by another process are unaffected by the
37       call of this process to munlock().  If any of the pages  in  the  range
38       specified by a call to munlock() are also mapped into other portions of
39       the address space of the calling process outside the  range  specified,
40       any  locks  established  on those pages via the other mappings are also
41       unaffected by this call.
42
43       Upon successful return from mlock(), pages in the specified range shall
44       be  locked  and memory-resident. Upon successful return from munlock(),
45       pages in the specified range shall be  unlocked  with  respect  to  the
46       address  space  of  the  process. Memory residency of unlocked pages is
47       unspecified.
48
49       Appropriate  privileges  are  required  to  lock  process  memory  with
50       mlock().
51

RETURN VALUE

53       Upon  successful  completion, the mlock() and munlock() functions shall
54       return a value of zero. Otherwise, no change is made to  any  locks  in
55       the address space of the process, and the function shall return a value
56       of -1 and set errno to indicate the error.
57

ERRORS

59       The mlock() and munlock() functions shall fail if:
60
61       ENOMEM Some or all of the address range specified by the addr  and  len
62              arguments  does  not  correspond  to  valid  mapped pages in the
63              address space of the process.
64
65       The mlock() function shall fail if:
66
67       EAGAIN Some or all of the memory identified by the operation could  not
68              be locked when the call was made.
69
70       The mlock() and munlock() functions may fail if:
71
72       EINVAL The addr argument is not a multiple of {PAGESIZE}.
73
74       The mlock() function may fail if:
75
76       ENOMEM Locking  the pages mapped by the specified range would exceed an
77              implementation-defined limit on the amount of  memory  that  the
78              process may lock.
79
80       EPERM  The calling process does not have appropriate privileges to per‐
81              form the requested operation.
82
83       The following sections are informative.
84

EXAMPLES

86       None.
87

APPLICATION USAGE

89       None.
90

RATIONALE

92       None.
93

FUTURE DIRECTIONS

95       None.
96

SEE ALSO

98       exec, exit(), fork(), mlockall(), munmap()
99
100       The Base Definitions volume of POSIX.1‐2017, <sys_mman.h>
101
103       Portions of this text are reprinted and reproduced in  electronic  form
104       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
105       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
106       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
107       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
108       event of any discrepancy between this version and the original IEEE and
109       The Open Group Standard, the original IEEE and The Open Group  Standard
110       is  the  referee document. The original Standard can be obtained online
111       at http://www.opengroup.org/unix/online.html .
112
113       Any typographical or formatting errors that appear  in  this  page  are
114       most likely to have been introduced during the conversion of the source
115       files to man page format. To report such errors,  see  https://www.ker
116       nel.org/doc/man-pages/reporting_bugs.html .
117
118
119
120IEEE/The Open Group                  2017                            MLOCK(3P)
Impressum