开发者

Sending signal from kernel to user space [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JAVA百科 Closed 10 years ago.

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 :

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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜