Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

munmap(2) [osf1 man page]

munmap(2)							System Calls Manual							 munmap(2)

NAME
munmap - Unmaps a mapped region SYNOPSIS
#include <sys/mman.h> int munmap ( void *addr, size_t len ); [Tru64 UNIX] The following definition of the munmap() function does not conform to current standards and is supported only for backward compatibility (see standards(5)): #include <sys/mman.h> int munmap ( caddr_t addr, size_t len ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: munmap(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the address of the region to be unmapped. Specifies the length in bytes of the region to be unmapped. DESCRIPTION
The munmap() function unmaps a mapped file or shared memory region. The addr and len parameters specify the address and length in bytes, respectively, of the region to be unmapped. The len parameter must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). If len is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE), the length of the region will be rounded up to the next multiple of the page size. The result of using an address which lies in an unmapped region and not in any subsequently mapped region is undefined. RETURN VALUES
Upon successful completion, the munmap() function returns 0 (zero). Otherwise, munmap() returns -1 and sets errno to indicate the error. ERRORS
If the munmap() function fails, errno may be set to one of the following values: The range [addr, addr + len) includes an invalid address. The addr parameter is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). The len parameter is 0 (zero). RELATED INFORMATION
Functions: mmap(2), sysconf(3) Standards: standards(5) delim off munmap(2)

Check Out this Related Man Page

MUNMAP(2)						      BSD System Calls Manual							 MUNMAP(2)

NAME
munmap -- remove a mapping SYNOPSIS
#include <sys/mman.h> int munmap(void *addr, size_t len); DESCRIPTION
The munmap() system call deletes the mappings for the specified address range, causing further references to addresses within the range to generate invalid memory references. DIRTY PAGE HANDLING
How munmap() handles a dirty page, depends on what type of memory is being unmapped: [Anonymous] If the memory is anonymous memory and if the last reference is going away, then the contents are discarded by definition of anonymous memory. [System V Shared] If the memory mapping was created using System V shared memory, then the contents persist until the System V memory region is destroyed or the system is rebooted. [File mapping] If the mapping maps data from a file (MAP_SHARED), then the memory will eventually be written back to disk if it's dirty. This will happen automatically at some point in the future (implementation dependent). Note: to force the memory to be written back to the disk, use msync(2). If there are still other references to the memory when the munmap is done, then nothing is done to the memory itself and it may be swapped out if need be. The memory will continue to persist until the last reference goes away (except for System V shared memory in which case, see above). RETURN VALUES
Upon successful completion, munmap returns zero. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
Munmap() will fail if: [EINVAL] The addr parameter was not page aligned (i.e., a multiple of the page size). [EINVAL] The len parameter was negative or zero. [EINVAL] Some part of the region being unmapped is not part of the currently valid address space. LEGACY SYNOPSIS
#include <sys/types.h> #include <sys/mman.h> The include file <sys/types.h> is necessary. int munmap(caddr_t addr, size_t len); The type of addr has changed. SEE ALSO
getpagesize(3), msync(2), munmap(2), mprotect(2), madvise(2), mincore(2), compat(5) HISTORY
The munmap() function first appeared in 4.4BSD. BSD
October 16, 2008 BSD
Man Page