Sending a signal from the kernel to user space

How to get a signal from kernel space to user space?

+5
source share
3 answers

To receive a signal from the kernel to user space, use the following code in your user space and the kernel code as follows:

user space:

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

Define the signal_handler_func function :

void signal_handler_func (int sig)
{

//handle the action corresponding to the signal here
}

Core 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.

+6
source

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

. , , fasync, : http://www.xml.com/ldd/chapter/book/ch05.html#t4

+1

-, NetLink, API . , , , IOCTL.

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

+1

All Articles