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
11

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

87       None.
88

APPLICATION USAGE

90       None.
91

RATIONALE

93       None.
94

FUTURE DIRECTIONS

96       None.
97

SEE ALSO

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