我需要保持它调用MMAP后打开一个文件? [英] do I need to keep a file open after calling mmap on it?
问题描述
我有一个映射的不少(100的)相当大的文件10-100MB每一个程序。我需要他们所有映射在同一时间。
I have a program that maps quite a few (100's) of sizeable files 10-100MB each. I need them all mapped at the same time.
在我打电话的那一刻打开
然后按 MMAP
在节目的开头,然后按则munmap
和关闭
结尾。
At the moment I am calling open
followed by mmap
at the beginning of the program, followed by munmap
and close
at the end.
我经常不得不调整打开的文件限制运行的ulimit -n
之前运行的程序。
Often I have to adjust the open files limit running ulimit -n
before running the program.
问题是我真正需要保持文件打开,或者我可以打开
MMAP
关闭
做一些大型的数据处理则则munmap
时,我finnished。
Question is do I actually need to keep the files open, or can I open
mmap
close
do some large data processing then munmap
when I'm finnished.
MMAP的手册页似乎并不十分清楚,我在这一个。
The man pages of mmap do not seem terribly clear to me on this one.
推荐答案
没有,至少不会在Linux上的罚款,关闭文件。
No, at least not on Linux it's fine to close the file.
手册页面明确规定:
在另一方面,在关闭文件描述符没有取消映射的区域。
On the other hand, closing the file descriptor does not unmap the region.
有关的便携性,我还检查href=\"http://pubs.opengroup.org/onlinepubs/7908799/xsh/mmap.html\"> POSIX手动,它说了同样的事情
For portability, I also checked the POSIX manual, it says the same thing (although even more clearly):
的MMAP()函数增加了一个额外参照与未由该文件描述符随后关闭()除去文件描述符fildes关联的文件。当没有更多的映射到文件此引用被除去。
The mmap() function adds an extra reference to the file associated with the file descriptor fildes which is not removed by a subsequent close() on that file descriptor. This reference is removed when there are no more mappings to the file.
这篇关于我需要保持它调用MMAP后打开一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!