本文介绍了侦听来自Linux内核或udev的硬件更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在安装和卸载存储设备上运行一些代码.
我如何在Linux上收听这些事件?
I need to run some code on storage device mounting and unmounting.
How can i listen for these events on linux?
- 我正在考虑添加一些 udev 规则来运行某些脚本(任何专有技术对此表示赞赏).
- 但是我宁愿使用守护程序在netlink套接字中监听内核中的事件(就像udev一样).
- 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.
推荐答案
您可以使用 libudev 或更方便的基于glib的 gudev 监视C语言中的udev事件.
You can use libudev or the more convenient, glib based gudev to monitor udev events in C.
这篇关于侦听来自Linux内核或udev的硬件更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!