Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I lock a directory in C on a linux machine

Will flock or lockf work on a directory? I there another way to lock a directory in C on a linux machine?

like image 270
user357498 Avatar asked Jan 11 '12 09:01

user357498


2 Answers

Yes, more info about using flock on file/directory can be found here

like image 140
Kris Avatar answered Nov 12 '22 08:11

Kris


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.

like image 27
Celada Avatar answered Nov 12 '22 09:11

Celada