Question about memory-mapped files

John M Collins (jmc@xisl.com)
Wed, 28 May 2003 17:32:59 +0100


Please cc me (jmc@removespam.xisl.com) in any reply as I'm not subscribed.

Could someone advise me on the answer to the following question:

If I invoke mmap to map a file to memory, and it succeeds, can I safely
close the original file descriptor and rely on the memory still being
mapped and the file still updated (possibly with mysnc)?

I've looked through the kernel (2.4) source and it seems I can. I've
tried a test program on my machine and also Solaris and HP and it works
OK the file getting updated.

On the Linux machine /proc/<pid>/maps seems to have all the right stuff
in after the file is closed.

The only thing that doesn't happen is that the file mod time doesn't get
changed (on any machine).

Of course "munmap" and "mremap" don't oblige you to pass an fd so it
would seem logical. But no manual page actually seems to say it.

Could anyone advise? Thanks.

-- 
John Collins Xi Software Ltd www.xisl.com

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/