监听来自 linux 内核或 udev 的硬件更改事件

发布于 2024-09-10 15:28:55 字数 253 浏览 3 评论 0原文

我需要在存储设备安装和卸载上运行一些代码。
我如何在Linux上监听这些事件?

  • 我正在考虑添加一些 udev 规则来运行一些脚本(这方面的任何专业知识受到赞赏)。
  • 但我更愿意用我的守护进程(就像 udev 那样)或类似的东西在某个 netlink 套接字中监听来自内核的事件。

I need to run some code on storage device mounting and unmounting.
How can i listen for these events on linux?

  • I was thinking on adding some udev rules to run some script (any know-how in this matter is appreciated).
  • But I would much rather listen for events from the kernel in some netlink socket with my daemon (just like udev does) or something like that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦欢 2024-09-17 15:28:55

您可以使用 libudev 或更方便的,基于 glib 的 gudev 来监视 C 中的 udev 事件。

You can use libudev or the more convenient, glib based gudev to monitor udev events in C.

凉世弥音 2024-09-17 15:28:55

你必须听“uevent ”信号。将回调附加到该信号并等待通知。

You have to listen to the "uevent" signal. Attach a callback to this signal and wait for the notification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文