在内核中,或者驱动层次进行对kill信号的捕获
具体的不介绍了,大家可以去查询,我是在内核驱动级别创建了一个线程,然后在线程中捕获这个信号的
然后发送kill 给这个线程,则线程就可以处理了
#include <linux/init.h>
#include <linux/module.h>
#include <linux/signal.h>
#include <linux/spinlock.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
int MyKernelThread(void *arg)
{
int n = 0;
//允许捕获的信号,如果没有标标记出来,用kill -9 是不捕获
allow_signal(SIGURG);
allow_signal(SIGTERM);
allow_signal(SIGKILL);
allow_signal(SIGSTOP);
allow_signal(SIGCONT);
while (!signal_pending (current)) //返回不为0表示有信号处理
{
ssleep(3);
printk("signal_pending %d\r\n", n++);
}
while(1)
{
printk("%d\r\n", n++);
ssleep(3);
//kthread_should_stop判断线程是否应该结束,返回true表示结束,false表示不结束
if(kthread_should_stop())
{
break;
}
}
return 0;
}