mmap()ed filenames?

Dan Nelson dnelson at allantgroup.com
Wed Jul 14 07:48:51 PDT 2004


In the last episode (Jul 14), Matthew Seaman said:
> On Wed, Jul 14, 2004 at 01:50:40AM -0700, Tyler Durdan wrote:
> > Is there a way to get the filename of an mmap()ed file in the
> > current process? For example, in Linux I can open /proc/self/maps
> > and get the filenames right there. However, if I try to open
> > /proc/getpid()/map on FBSD, the only mapping info is "vnode" or
> > "default" on FBSD 4.10-BETA.
> >                          
> > Is there any way to convert this info into the filenames of mapped
> > files?
> 
> That's a generally hard problem -- given some sort of open file, find
> the file name it was opened as.  Most unixoid OSes don't record
> filenames used on open(2) to go with file descriptors or areas of
> mmapped data because it's a waste of space.  And there's no reliable
> way to work backwards from the open file to a file name.

You can use the lsof command in ports, which will dig through the
kernel's file name cache and print at least some names.  FreeBSD 5.x's
/proc/*/map does the same thing for you.  If you use lsof, for any
files missing filenames, you can try and find the name by running "find
/ -inum ####", where #### is the number in the NODE column.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list