How to synchronize file I/O of many independent applications on Linux? How to synchronize file I/O of many independent applications on Linux? linux linux

How to synchronize file I/O of many independent applications on Linux?


I believe there are three possible solutions

1) Make all programs to use a custom file I/O library that implement the features that you need. This solution may not be feasible if you do not have access to the source code. You may also consider to use mmap so that changes are written to memory. You use a background process to synchronize dirty pages to existing or new files.

2) Replace standard C/C++ libraries (such as libc.so) that affected programs would use. You could use ldd to find out library dependency. You need to update source code for standard C/C++ to implement features that you need. This may be too difficult for most people.

3) Create your file system. You may refer to many articles in the internet, such as https://kukuruku.co/post/writing-a-file-system-in-linux-kernel/. This is the best and cleanest solution.

Hope it helps.


Rename is atomic. It is up to your application to compare "eTags" of source and destination (possibly under appropriate locks) before deciding on calling rename().


mmap seems to have this kind of protection your looking for:https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/func-mmap.html

prot The prot argument describes the desired memory protection. Regardless of the device type and the direction of data exchange it should be set to PROT_READ | PROT_WRITE, permitting read and write access to image buffers. Drivers should support at least this combination of flags.