Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Thread Tools Display Modes
  #1   (View Single Post)  
Old 31st August 2011
jsmith6134 jsmith6134 is offline
Port Guard
Join Date: May 2009
Posts: 10
Default list open files - fstat?

I am trying to find the list of open files for a process. I did a search and found:


I figure that I should be able to use fstat. However, it does not display the file's name. According to the name page there should be a 'NAME' column. From the man page:

The following fields are printed:
NAME If filename arguments are specified and the -f flag is not, then
this field is present and is the name associated with the given
file. Normally the name cannot be determined since there is no
mapping from an open file back to the directory entry that was
used to open that file. Also, since different directory entries
may reference the same file (via ln(1)), the name printed may not
be the actual name that the process originally used to open that

Not sure how to get it to display any file names. I tried using "-f" and a mount point or directory, but does not make a difference; no name column is displayed. I also tried as root, to ensure that there is no permission problem.

I also used the search for the forums here, but nothing came up. Am I misreading the man page?
Reply With Quote
  #2   (View Single Post)  
Old 31st August 2011
rocket357's Avatar
rocket357 rocket357 is offline
Real Name: Jonathon
Wannabe OpenBSD porter
Join Date: Jun 2010
Posts: 429

Why not use lsof?

Are you trying to go as "stock" as possible? Just curious.

The "NAME" field is only present if you *specify a file argument* (i.e. fstat /path/to/some/file) and no -f option. Specifying -f makes "NAME" go away.
Linux/Network-Security Engineer by Profession. OpenBSD user by choice.

Last edited by rocket357; 31st August 2011 at 03:26 AM.
Reply With Quote
  #3   (View Single Post)  
Old 31st August 2011
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223

It simply isn't practical to reverse the name of a the inode without traversing through the entire filesystem hierarchy.. inode numbers can obviously conflict.

The inode does NOT contain the filename, as there can be many references, or hard "links" to a file.

A lot of people don't realize that directory inodes are special, this where name mappings for inodes are stored.

Once you have the inode, you can use find -inum or ls -i to locate it.

Last edited by BSDfan666; 31st August 2011 at 03:56 AM.
Reply With Quote
  #4   (View Single Post)  
Old 2nd September 2011
jsmith6134 jsmith6134 is offline
Port Guard
Join Date: May 2009
Posts: 10

Thanks for the information.

Yes, I prefer to be as stock as possible. It seems silly to add unnecessary software when not needed. Also, it seems wise to know what is provided in the base in case one is stuck with just the base system.

Seems counter intuitive that the name is supplied only when one specifies the path.

Good point about the inode and the mapping.

Good to know that "fstat" and "find" will give the actual files open by a process. From what I tested, it can be quite slow using find if there are a lot of files on the mount. I found '-x' argument to 'find' reduce the time dramatically.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
List of 4.7 packages? guitarscn OpenBSD Packages and Ports 5 23rd August 2010 05:37 PM
Can't open PDF files, FBSD 7.2-release Mantazz FreeBSD Ports and Packages 7 24th December 2009 01:10 PM
How to get a list of volumes? PeterSteele Programming 12 17th July 2008 09:32 AM
How to view & open DOCX files in Ubuntu/OpenOffice. unixdude Other BSD and UNIX/UNIX-like 0 11th July 2008 08:38 AM
fstat | grep internet | grep -v -e '>' -e '<' mfaridi OpenBSD General 4 10th June 2008 09:58 PM

All times are GMT. The time now is 10:31 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick