You must use file locking. On Unix, this is flock
; on Windows, this is LockFile
.
However, the fact that your reading process is an error probably indicates that you did not open the file in read-only mode in this process. You must specify the correct flags for read-only access or from an OS point of view, you have two authors.
Both operating systems support read-write locks, where unlimited readers are allowed, but only in the absence of writers, and only one writer at a time will have access.
Since you say that your system is multiprocessor (i.e. not multithreaded), you cannot use a condition variable (if it is not used in interprocess shared memory). You also cannot use one writer as a coordinator if you do not want to transfer data there through sockets or shared memory.
source share