日期:2014-05-16  浏览次数:21015 次

多进程mmap同一个文件,当一个进程退出时,是否需要unmap
多进程mmap同一个文件,当一个进程退出时,是否需要unmap?

------解决方案--------------------
进程退出时不unmap没关系。
但是如果进程里面多次mmap该文件,但是每次访问完不进行unmap,就会发现该进程占的虚拟内存不断增长。
------解决方案--------------------
不需要umap。
进程退出时,系统会销毁所有内存资源。

参考man手册:
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.
------解决方案--------------------
不需要umap。
进程退出时,系统会销毁所有内存资源。