Do I need to keep a file open after calling mmap on it?

后端 未结 1 1084
情书的邮戳
情书的邮戳 2020-12-08 09:20

I have a program that maps quite a few (100\'s) of sizable files 10-100MB each. I need them all mapped at the same time.

At the moment I am calling open

相关标签:
1条回答
  • 2020-12-08 09:58

    No, at least not on Linux it's fine to close the file.

    The manual page clearly states:

    On the other hand, closing the file descriptor does not unmap the region.

    For portability, I also checked the POSIX manual, it says the same thing (although even more clearly):

    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.

    0 讨论(0)
提交回复
热议问题