mmap() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint
#include <sys/mman.h> 

void *mmap(void *start, size_t length, int prot, int flags, 
           int fd, off_t offset); 

int munmap(void *start, size_t length); 


void *mmap(void *start, size_t length, int prot, int flags, 
           int fd, off_t offset); 


int munmap(void *start, size_t length); 


The
prot argument describes the desired memory protection (and must not
conflict with the open mode of the file). It is either
PROT_NONE or is the bitwise OR of one or more of the other PROT_* flags.


The above three flags are described in POSIX.1-2001.
Linux also knows about the following non-standard flags:


fd should be a valid file descriptor, unless
MAP_ANONYMOUS is set.
If
MAP_ANONYMOUS is set, then
fd is ignored on Linux.
However, some implementations require
fd to be -1 if
MAP_ANONYMOUS (or
MAP_ANON) is specified,
and portable applications should ensure this.


offset should be a multiple of the page size as returned by
getpagesize(2).


Memory mapped by
mmap() is preserved across
fork(2),
with the same attributes.


A file is mapped in multiples of the page size. For a file that is not
a multiple of the page size, the remaining memory is zeroed when mapped,
and writes to that region are not written out to the file. The effect of
changing the size of the underlying file of a mapping on the pages that
correspond to added or removed regions of the file is unspecified.


The
munmap() system call deletes the mappings for the specified address range, and
causes further references to addresses within the range to generate
invalid memory references.  The region is also automatically unmapped
when the process is terminated.  On the other hand, closing the file
descriptor does not unmap the region.


The address
start must be a multiple of the page size. All pages containing a part
of the indicated range are unmapped, and subsequent references
to these pages will generate SIGSEGV. It is not an error if the
indicated range does not contain any mapped pages.


For file-backed mappings, the
st_atime field for the mapped file may be updated at any time between the
mmap() and the corresponding unmapping; the first reference to a mapped
page will update the field if it has not been already.


The
st_ctime and
st_mtime field for a file mapped with
PROT_WRITE and
MAP_SHARED will be updated after
a write to the mapped region, and before a subsequent
msync() with the
MS_SYNC or
MS_ASYNC flag, if one occurs.


In kernels before 2.6.7, the
MAP_POPULATE flag only has effect if
prot is specified as
PROT_NONE. 
getpagesize (2)
getpagesize (2)
mincore (2)
mincore (2)
mlock (2)
mlock (2)
mmap2 (2)
mmap2 (2)
mremap (2)
mremap (2)
msync (2)
msync (2)
remap_file_pages (2)
remap_file_pages (2)
setrlimit (2)
setrlimit (2)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page