[lug] Polling a file under linux

Rob Judd rjudd at mlug.missouri.edu
Mon Apr 21 10:57:04 MDT 2003


I have a C/C++ application that has to connect to an IP address every few
minutes/seconds (exact timing is not yet clear).  The IP address may
change as the application is running, and the exact address is stored in
/etc/myapp.config

Since this file may change at any time I have to check it before each
connection.  It seems to me that my options are

1. read the contents of the file before every connection
2. stat the file before every connection

both of these are rather expensive, especially if connections are made
several times a second.

Is there a better way to poll a file to see when it changes?  (This is in
C or C++)

Thanks, Rob




More information about the LUG mailing list