Assume that:
- 1) I have a folder on Linux that I only have "read" and "execute" permissions.
- 2) Somebody with higher privilege (with a "write" permission) will put some files into that folder.
- 3) Multiple processes of a program running in parallel will read and perform some data processing on the files.
Requirement: A file is read by only one process. When done, the file is either removed or moved to a different place. All the files will not be written/edited. For example, I have 5 files and 2 processes running in parallel. I need to ensure that process 1 will read and perform some works on files 1, 3, and 5. Process 2 will read and perform some works on files 2 and 4. It means computational distributions are done at the file-level. We are not going to distribute computations inside files.
On Linux, there are two functions that can place an exclusive lock: flock and fcntl. They work interchangeably and respect the locks placed by the others. The problem is both the functions require the "write" permission.
Boost library also has the boost::interprocess::file_lock::try_lock()
function. It does the same job as the above two functions. It also requires the "write" permission.
Are there any other methods that I can place an exclusive lock on files that I don't have "write" permission?