Sending signal from kernel to user space [closed]

十年热恋 提交于 2021-02-18 12:38:27

问题


How to get signal from kernel space to user space?


回答1:


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

user space application :

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

define signal_handler_func function :

void signal_handler_func (int sig)
{

//handle the action corresponding to the signal here
}

kernel Space Module :

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 is the PID of the user application.




回答2:


Use the kernel API function kill_proc_info(int sig, struct siginfo *info, pid_t pid)

NOTE This is actually a bad answer. The functions does send a signal to user space but the right way to do this, as the asker intended is to use the fasync character device method as documented here: http://www.xml.com/ldd/chapter/book/ch05.html#t4




回答3:


There is something called a NetLink interface which provides a set of API's for communication between a kernel process and a user process.It is similar to the socket interface and the communication is asynchronous and hence is preferred to IOCTL.

Overview here: http://www.linuxjournal.com/article/7356



来源:https://stackoverflow.com/questions/5634466/sending-signal-from-kernel-to-user-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!