If you have control over the writing process, you should use mmap() with MAP_SHARED for both reading and writing. Thus, the reader will see the changes made by the author almost immediately.
Also note that when you open a file, Linux does not take snapshots of the data in the file, so you should see the changes that are made to the file, even if you just use read() and lseek() .
To determine if a file has been modified / opened / accessible / on Linux, you can use the inotify API (see inotify manpage ). This allows you to make the process wait for an event that interests you until it happens (as opposed to regular polling). You can also use epoll() or the more traditional select() to achieve a similar result.
source share