linux - 从内核向用户空间发送信号

标签 linux linux-device-driver embedded-linux

<分区>

如何从内核空间获取信号到用户空间?

最佳答案

要从内核到用户空间获取信号,请在您的用户空间和内核空间代码中使用以下代码,如下所示:

用户空间应用:

signal(SIGIO, &signal_handler_func); 
fcntl(fd, F_SETOWN, getpid());
oflags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, oflags | FASYNC);

定义signal_handler_func函数:

void signal_handler_func (int sig)
{

//handle the action corresponding to the signal here
}

内核空间模块:

int ret = 0;
struct siginfo info;
memset(&info, 0, sizeof(struct siginfo));
info.si_signo = SIG_TEST;
info.si_code = SI_QUEUE;
info.si_int = 1234;  

send_sig_info(SIG_TEST, &info, t);//send signal to user land 

t 是用户应用程序的 PID。

关于linux - 从内核向用户空间发送信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5634466/

相关文章:

embedded - u-boot根据GPIO状态选择启动分区

linux - 静态库的 Yocto 构建失败,错误为 "No Match Found"

Android 重启命令 - 谁调用reboot_main()?

java - 如何在 Cpanel 管理的服务器上安装 java?

linux - 字符串中的 Shell 脚本参数

linux-kernel - 从内核空间中的 block 设备读取

c - Linux 4.5 GPIO 中断通过 Xilinx Zynq 平台上的 Devicetree

linux-kernel - 内核中的类似 strerror 的功能?

python - USB串口数据发送乱码

linux - 从 shell 编写 shell 脚本,还是从 shell 脚本编写?