Offset 0 indicates mapping from the
In the following example, the program maps the first 4 KB of a file
passed whose name is passed as a command line argument:
int main(int argc, char *argv)
void * pregion;
if (fd= open(argv, O_RDONLY) <0)
perror("failed on open");
/*map first 4 kilobytes of fd*/
pregion=mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
/*..access mapped memory*/
The munmap() function unmaps a mapped region.
int munmap(caddr_t addr, int length);
addr is the regions address and length specifies how much of the memory
should be unmapped (you may unmap a portion of a mapped region).