如果附加了一个新的接口,如何得到Linux内核的通知?

时间:2022-08-17 02:09:24

I want to be able to detect when a new external device is connected to the linux system and upon that send a notification message to a running process.

我希望能够检测何时一个新的外部设备连接到linux系统,并在此基础上向正在运行的进程发送一条通知消息。

I was wondering if there is any other solution than periodically scan for /dev/ and detect if anything has changed.

我想知道除了定期扫描/dev/并检测是否有任何变化之外是否还有其他解决方案。

1 个解决方案

#1


3  

While you can use udev, the underlying mechanism is netlink. Interfaces themselves are not normally in /dev, but do show up under /sys/class/net as sub-directories. However, the hotplug.txt gives a good start to inspecting kernel events. Run the sample code and examine the netlink data when an interface is connected. The text is ASCII that any user space application can parse and use.

虽然可以使用udev,但底层机制是netlink。接口本身通常不在/dev中,但在/sys/class/net下显示为子目录。然而,热插拔。txt为检查内核事件提供了良好的开端。运行示例代码,并在接口连接时检查netlink数据。文本是任何用户空间应用程序都可以解析和使用的ASCII。

#1


3  

While you can use udev, the underlying mechanism is netlink. Interfaces themselves are not normally in /dev, but do show up under /sys/class/net as sub-directories. However, the hotplug.txt gives a good start to inspecting kernel events. Run the sample code and examine the netlink data when an interface is connected. The text is ASCII that any user space application can parse and use.

虽然可以使用udev,但底层机制是netlink。接口本身通常不在/dev中,但在/sys/class/net下显示为子目录。然而,热插拔。txt为检查内核事件提供了良好的开端。运行示例代码,并在接口连接时检查netlink数据。文本是任何用户空间应用程序都可以解析和使用的ASCII。