简体   繁体   English

如何确定用户空间进程是否已连接到netlink内核模块?

[英]how to find out if userspace process is connected to netlink kernel module?

I'm currently writing a little linux kernel module (> 3.10) which should communicate with a userspace process through a netlink socket. 我目前正在编写一个小的Linux内核模块(> 3.10),该模块应该通过netlink套接字与用户空间进程进行通信。 Receiving and sending data on both sides is working fine. 双方的接收和发送数据工作正常。 But how is it possible, inside the kernel module, to find out if there is any userspace process connected? 但是,如何在内核模块内部找出是否连接了任何用户空间进程?

At the moment I just wait for the process to send data to the module, and save the process pid for the answer. 此刻,我只是等待流程将数据发送到模块,并保存流程pid作为答案。 But what if my module should send data periodically from kernel- to userspace, without any requests from the userspace process? 但是,如果我的模块应该定期从内核到用户空间发送数据,而没有用户空间进程的任何请求,该怎么办? Is it possible to find out if there are any sockets open? 是否可以找出是否有插座打开?

I found some interesting callback pointers in struct proto , but they seem not to be used (for netlink sockets?). 我在struct proto发现了一些有趣的回调指针,但似乎不使用它们(用于netlink套接字?)。

Kernel space <> User space communicate through kernel's netlink sockets. Kernel space <> User space通过内核的netlink套接字进行通信。 They have hotplug [ udev , modprob , etc] events [add, change, remove, etc] which fire when major state changes happens. 它们具有hotplug [ udevmodprob等]事件[add,change,remove等],这些事件会在发生主要状态更改时触发。

If you listen to those events in your system, you could be able to dig further. 如果您在系统中收听这些事件,则可以进一步挖掘。

If you have a udev hotplug, you can use below command, or there are some older commands for the same: 如果您有udev热插拔,则可以使用以下命令,或者使用以下命令:

udevadm monitor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM