How do I find out if a file has been updated by another process?


This is close to being a Frequently Unanswered Question, because people
asking it are often looking for some notification from the system when a
file or directory is changed, and there is no portable way of getting
this. (IRIX has a non-standard facility for monitoring file accesses,
but I've never heard of it being available in any other flavour.)



In general, the best you can do is to use fstat() on the
file. (Note: the overhead on fstat() is quite low, usually much
lower than the overhead of stat().) By watching the mtime and
ctime of the file, you can detect when it is modified, or
deleted/linked/renamed. This is a bit kludgy, so you might want to
rethink why you want to do it.




[an error occurred while processing this directive]