Mmap,mmap64,munmap---Map or unmap files or devices into memory
void *mmap (void* addr,size_t length, int prot, int flags, int fd, off_t offset);
void *mmap64 (void* addr,size_t length, int prot, int flags, int fd, off_t offset);
int Munmap (void *addr, size_t lenght);
Mmap function creates a new mapping in the virtual address space of the the calling process. The sharting address for the new mapping is
Specipfied in addr. The lenght argument specifies the lenght of the mapping.
If addr is NULL and then the kernel choses the address in which to create the mapping; The most portable method of createing a new
Mapping. If addr is isn't NULL, then the kernel takes it as a hint on where to place mapping; On Linux, the mapping is created at a Nerby
Page boundary. The address of the new mapping is returned as the result of the
The contents of a file mapping. is initialized using lenght bytes starting at offset int the file referred to by the file descriptor FD. Offset must
Be a mutiple of the page size as returned by sysconf (Sc_page_size).
The prot argument describes the desired memory protection of the mapping. It is either Prot_none or the bitwise of one RO more of the the the following flags
Simple
int main ()
{
int fd = open ("A.txt", o_creat| o_rdwr,0666);
if (!FD)
Perror ("open"), exit (-1);
Ftruncate (Fd,sizoef (char) *6);
void *p = Mmap (0,sizeof (char*) *6,prot_write,map_shared,fd,0);
char* pc = P;
strncpy (PC, "Masato", 6);
Munmap (p,sizeof (char) *6);
Close (FD);
file* PF = fopen ("A.txt", "R");
Char buf[10] ={0};
Fgets (Buf,sizeof (BUF), PF);
Fwrite (Buf,strlen (BUF), 1,stdout);
Fclose (PF);
return 0;
}
Linux-function-mmap,mmap64,munmap;