How to lock a directory in C on a Linux machine

Will flock or lockf work in a directory? Do I have another way to lock a directory in C on a Linux machine?

+4
source share
2 answers

You cannot open the directory for recording, so this means that you cannot get a write lock.

Even if you could, please keep in mind that flock and fcntl and other types of POSIX locks are advisory, therefore they do not actually interfere with software that does not take into account blocking from actions.

Perhaps you want to see something like xfs_freeze , which locks the entire file system. This is probably not useful for your use case.

+4
source

Yes, more information on using flock in the file / directory can be found here.

+1
source

Source: https://habr.com/ru/post/1390394/


All Articles