4

I'm familiar with how to use inotify to monitor for changes to named files within directories, but I'm currently wondering if it's possible to use it to watch for modifications of a file only known by an opened filehandle. Is such a thing possible?

inotify_add_watch is documented as taking just a pathname, and I don't see any other functions to add such watches.

Failing this, is there some way I can take an open filehandle and convert it somehow back into a pathname, such that I can pass that to inotify?

Edit: Actually it doesn't strictly have to be inotify, I'm just looking for a mechanism to be notified when regular files have been appended to or modified - think tail -f and similar.

LeoNerd
  • 8,344
  • 1
  • 29
  • 36
  • @Friek: epoll() cannot be used on regular filehandles. epoll_ctl(2) says it returns an EPERM for non-supported filehandles. I have observed this experimentally. – LeoNerd Jun 03 '12 at 17:11
  • Out of curiosity, what makes your file handles unsupported for epoll then? – Friek Jun 03 '12 at 17:25
  • @Friek: epoll works on blocking-style filehandles like sockets, pipes, TTYs, etc. It is similar to select() and poll(). IFREG filehandles are always read- and write-ready according to select() and poll() but this historical curiosity is not supported by epoll. – LeoNerd Jun 04 '12 at 13:43

1 Answers1

3

You can use "/proc/x/fd/y" as the pathname to inotify_add_watch , where x is your process id and y is the file handle id.

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319