I need to write an application that spits out log entries to a regular file at a very fast rate. Also, there will be another process, that can read the same file concurrently at the time, other process would be writing to it.
I have following questions
-
How does read() determine EOF, specially in the case, where the underlying file could be concurrently being modified?
-
Is it possible for read() to return partially written data from the other process write? For example, the write process wrote half a line and read would pick that half line and return?
The application would be written in C on linux 2.6.x using Ex4 filesystem
UPDATE:
Below link points to the patch, that locks inode in EXT4, before reading and writing.
http://patchwork.ozlabs.org/patch/91834/
When you try to
read()past the end of the file it returnsEOF. You can still seek the file back and forward and read again (only if the file descriptor refers to a file, not a pipe or socket though).Quite possible.