🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Recently-accessed files and devices

Started by
2 comments, last by truthsayer 16 years, 4 months ago
Hi. I want to get a list of whatever processes recently accessed a given file (by name or descriptor) or block device. Where is this information logged? Do I have to enable a certain type of logging?
Advertisement
In /proc/yourpid/fd you can see the currently opened files.
You could make little script which searches all processes for having a specific file opened.

I don't know of any better way.
Quote: Original post by spraff
Hi. I want to get a list of whatever processes recently accessed a given file (by name or descriptor) or block device. Where is this information logged? Do I have to enable a certain type of logging?

There's no way to get a list of processes that recently accessed a filesystem object or a device because that's done by the kernel, not a process. There may be a way to get the kernel to report what process made what system call, but that's not necessarily useful information since processes come and go rapidly and you're going to have difficulty mapping pid to programs after the process is gone.

What you can do quite effectively on Linux at least is to watch an inode for various transitions and try to capture which process is acessing the file at that point. Use the inotify calls to watch the inode. You are still liable to race conditions so your information is not guaranteed to be completely accurate, but at least you'll be able to get a good idea of file activity.

Stephen M. Webb
Professional Free Software Developer

Quote: Original post by spraff
Hi. I want to get a list of whatever processes recently accessed a given file (by name or descriptor) or block device. Where is this information logged? Do I have to enable a certain type of logging?


For what purpose do you need to do this?
My rating perfectly reflects the pathetic yes-men in-crowd attitude of this forum.

This topic is closed to new replies.

Advertisement