简体   繁体   English

如何从内核模块向用户空间应用程序发送“信号”?

[英]How to send a “signal” from kernel module to user-space application?

I have a Linux kernel module which contains the interrupt handler, and would like to somehow notify the user-space application after the interrupt was handled. 我有一个Linux内核模块,其中包含中断处理程序,并希望在处理完中断后以某种方式通知用户空间应用程序。 Please tell me, how to do it? 请告诉我,怎么做?

Use the netlink . 使用netlink

Netlink socket is a special IPC used for transferring information between kernel and user-space processes. Netlink套接字是一种特殊的IPC,用于在内核和用户空间进程之间传输信息。 It provides a full-duplex communication link between the two by way of standard socket APIs for user-space processes and a special kernel API for kernel modules. 它通过用于用户空间进程的标准套接字API和用于内核模块的特殊内核API在两者之间提供全双工通信链接。 Netlink socket uses the address family AF_NETLINK, as compared to AF_INET used by TCP/IP socket. 与TCP / IP套接字使用的AF_INET相比,Netlink套接字使用地址族AF_NETLINK。 Each netlink socket feature defines its own protocol type in the kernel header file include/linux/netlink.h. 每个netlink套接字功能在内核头文件include / linux / netlink.h中定义自己的协议类型。

  • You can always use normal sockets, like UDP or UNIX. 您始终可以使用普通套接字,如UDP或UNIX。
  • You can export this information via /proc or /sys (see this question). 您可以通过/proc/sys导出此信息(请参阅问题)。
  • You can use Netlink (see this question). 您可以使用Netlink(请参阅问题)。

I'm directly answering this question as it's the top result in Google for "kernel send signal to user space". 我正在直接回答这个问题,因为这是谷歌“向用户空间发送内核信号”的最佳结果。

I typically use signal to kill the userspace process to examine it's stack as it calls ioctls. 我通常使用signal来杀死用户空间进程,以便在调用ioctl时检查它的堆栈。 Typically the following works for me: 通常,以下内容适用于我:

force_sig(SIGSEGV, current);

暂无
暂无

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

相关问题 如何从内核模块扫描用户空间内存 - How to scan user-space memory from a kernel module 在不依赖输入调用的情况下,自动将消息从内核模块发送到用户空间应用程序。 来自用户空间 - Autonomically sending a message from kernel-module to user-space application without relying on the invoke of input. from user-space 可以使用NETLINK_ROUTE通道将消息从内核模块发送到用户空间程序吗? - Can NETLINK_ROUTE channel be used to send messages from kernel module to a user-space program? 如何在内核模块中获取数组的地址,以便能够在用户空间应用程序中使用它? - How to get the address of an array in kernel module so I'll be able to use it within a user-space application? 从内核分配用户空间内存 - allocate user-space memory from kernel 执行/调用用户空间程序,并从内核模块获取其pid - Execute/invoke user-space program, and get its pid, from a kernel module 如何在内核模块中访问由用户空间进程创建的/ dev / shm下的tmpfs文件? - How to access tmpfs file under /dev/shm, created by user-space process, in a kernel module? 从内核空间执行用户空间功能 - Executing a user-space function from the kernel space UDP数据包从内核到Linux中用户空间的路径 - Path of the UDP packet from kernel to user-space in Linux 当我们从用户空间调用任何套接字时,内核如何知道要调用哪个驱动程序? - How kernel know which driver to be called when we are calling any socket from user-space?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM