首页 > 代码库 > C 语言 mmap

C 语言 mmap

/**@author cody*@date 2014-08-12*@description *//*#include <sys/mman.h>void *mmap(void *addr,size_t len,int prot,int flag,int filedes,off_t off);int munmap(void *addr,size_t len);*/#include <stdlib.h>#include <sys/mman.h>#include <fcntl.h>void MmapFile(){    int *p;    int fd = open("hello",O_RDWR);    if(fd <  0){        perror("open hello");        exit(1);    }    p = mmap(NULL,6,PROT_WRITE,MAP_SHARED,fd,0);    if(p == MAP_FAILED){        perror("mmap");    }    close(fd);    p[0] = 0x30313233;    munmap(p,6);}int main(int argc, char const *argv[]){    MmapFile();    return 0;}