Will flock or lockf work on a directory? I there another way to lock a directory in C on a linux machine?
Yes, more info about using flock on file/directory can be found here
You can't open a directory for writing, so that means you can't get a write lock on it.
Even if you could, please keep in mind that flock
and fcntl
and other kinds of POSIX locks are advisory, so they don't actually prevent software that doesn't respect the lock from doing things.
Maybe you want to look at something like xfs_freeze
which locks an entire filesystem. It's probably not useful for your use case though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With