从内核向用户空间发送信号 [英] Sending signal from kernel to user space

查看:74
本文介绍了从内核向用户空间发送信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to get signal from kernel space to user space?

推荐答案

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

To get the signal from kernel to user space use the following code in your user space and kernel space code as below :

用户空间应用程序:

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.

t is the PID of the user application.

这篇关于从内核向用户空间发送信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆