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

旧巷老猫 提交于 2019-12-12 10:46:36

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/8816941/how-can-i-lock-a-directory-in-c-on-a-linux-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!