Listen for harware change events from the linux kernel or udev

早过忘川 提交于 2019-12-22 08:00:05

问题


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.

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/3255174/listen-for-harware-change-events-from-the-linux-kernel-or-udev

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