开发者

Listen for harware change events from the linux kernel or udev

I need to run some code on storage device mounting and unmounting.

How can i listen for these event开发者_StackOverflow中文版s 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜