The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


munmap - unmap pages of memory


#include <sys/mman.h>

int munmap(void *addr, size_t len);


The function munmap() removes any mappings for those entire pages containing any part of the address space of the process starting at addr and continuing for len bytes. Further references to these pages result in the generation of a SIGSEGV signal to the process. If there are no mappings in the specified address range, then munmap() has no effect.

The implementation  will require that addr be a multiple of the page size {PAGESIZE}.

If a mapping to be removed was private, any modifications made in this address range will be discarded.

Any memory locks (see mlock() and mlockall()) associated with this address range will be removed, as if by an appropriate call to munlock().

The behaviour of this function is unspecified if the mapping was not established by a call to mmap().


Upon successful completion, munmap() returns 0. Otherwise, it returns -1 and sets errno to indicate the error.


The munmap() function will fail if:
Addresses in the range [addr, addr + len) are outside the valid range for the address space of a process.
The len argument is 0.
The addr argument is not a multiple of the page size as returned by sysconf().




The third form of EINVAL above is marked EX because it is defined as an optional error in the POSIX Realtime Extension.




mmap(), sysconf(), <signal.h>, <sys/mman.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]