文件删除/修改期间的 libevent
是否可以使用 libevent 来监视文件删除/更新?
假设 /var/log/file.1 被删除,我想在我的程序中报告它。这可能吗?如果是,怎么办?
我的操作系统是 Linux,我想创建一个在某些操作系统操作期间触发消息的恶魔。
我在哪里可以找到更多信息?
Is to possible to use libevent to monitor a file removal/update?
Assuming that /var/log/file.1 is removed I want to report it in my program. Is this possible? If yes, how?
My operating system is Linux and I want to create a demon that fires messages during some operating system actions.
Where can I find more information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的代码特别针对 Linux,您可以使用
inotify(7)< /code>
设施代替。它有一个非常简单的编程接口,旨在监视文件更改和删除,而 libevent 的目的略有不同:监视一组描述符,并在其中任何一个准备好时收到通知阅读/写作。
我不确定
libevent
是否包装了inotify
,因为所有其他操作系统的libevent
支持并不提供类似的功能。If your code is particularly targeted for Linux, you can make use of the
inotify(7)
facility instead. It has a very simple programming interface and is meant to monitor file changes and deletions, while the purpose oflibevent
is slightly different: to watch over a group of descriptors and be notified whenever any of them is ready for reading/writing.I am not sure if
libevent
wrapsinotify
at all, because similar facilities are not provided by all other OS'eslibevent
supports.只需使用一些简单的逻辑,您就可以检查该文件是否被删除?
您还可以通过检查 struct stat 的另一个元素来检查文件的更多属性
just using some simple logic you can check whether this file is deleted or not ?
you can also check more property of file by checking another element of struct stat