<分区>
如何从内核空间获取信号到用户空间?
<分区>
如何从内核空间获取信号到用户空间?
最佳答案
要从内核到用户空间获取信号,请在您的用户空间和内核空间代码中使用以下代码,如下所示:
用户空间应用:
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/