I have a file and a lot of process (and process threads) are accessing it.
I want to monitor the file to get a listing of what all processes tried to access the file. Being able to record the timestamps also would be excellent for logging purposes, though I can do without it.
Is there any Unix utility that does something similar?
In case no such utility exists, how should I program this using a script (shell, Perl) or a program (C, C++)?
Under Linux, inotify might be what you're looking for.
I think the basic functionality you're looking for is in the UNIX command fuser
.
This will tell you what processes are using a file (or port if you like).
FAM - File Alteration Monitor http://oss.sgi.com/projects/fam/ or Gamin http://people.gnome.org/~veillard/gamin/
might help you (gamin seems maintained while I cannot say the same for FAM).
You can attach your app to FAM/Gamin and then you'll be notified if something happened with the watched files. For details I suggest: http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=bks&fname=/SGI_Developer/books/IIDsktp_IG/sgi_html/ch08.html
You might want to look at lsof
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With