如何在linux机器上的C中锁定一个目录 [英] How can I lock a directory in C on a linux machine

查看:349
本文介绍了如何在linux机器上的C中锁定一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

flock或lockf会在目录上工作吗?
我有另一种方法在linux机器上的C中锁定目录?

解决方案

你不能打开目录为写,所以这意味着你不能得到一个写锁。



即使可以,请记住, flock fcntl 和其他类型的POSIX锁是建议的,所以它们实际上不会阻止不遵守锁的软件做事情。



也许你想看看像 xfs_freeze 这些锁定整个文件系统的东西。这可能对您的用例无效。


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

解决方案

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.

这篇关于如何在linux机器上的C中锁定一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆