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
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       The appropriate privilege is  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
67       The mlock() function shall fail if:
68
69       EAGAIN Some or all of the memory identified by the operation could  not
70              be locked when the call was made.
71
72
73       The mlock() and munlock() functions may fail if:
74
75       EINVAL The addr argument is not a multiple of {PAGESIZE}.
76
77
78       The mlock() function may fail if:
79
80       ENOMEM Locking  the pages mapped by the specified range would exceed an
81              implementation-defined limit on the amount of  memory  that  the
82              process may lock.
83
84       EPERM  The  calling  process does not have the appropriate privilege to
85              perform the requested operation.
86
87
88       The following sections are informative.
89

EXAMPLES

91       None.
92

APPLICATION USAGE

94       None.
95

RATIONALE

97       None.
98

FUTURE DIRECTIONS

100       None.
101

SEE ALSO

103       exec(), exit(), fork(), mlockall(), munmap(), the Base Definitions vol‐
104       ume of IEEE Std 1003.1-2001, <sys/mman.h>
105
107       Portions  of  this text are reprinted and reproduced in electronic form
108       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
109       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
110       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
111       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
112       event of any discrepancy between this version and the original IEEE and
113       The  Open Group Standard, the original IEEE and The Open Group Standard
114       is the referee document. The original Standard can be  obtained  online
115       at http://www.opengroup.org/unix/online.html .
116
117
118
119IEEE/The Open Group                  2003                            MLOCK(3P)
Impressum