#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 main_thread(void *arg)
{
int n = 0;
//用来捕获应用的INT、TERM、KILL、USR信号,运行通过接受信号停止内核线程
allow_signal(SIGINT);
allow_signal(SIGTERM);
allow_signal(SIGURG);
allow_signal(SIGKILL);
allow_signal(SIGSTOP);
allow_signal(SIGCONT);
while (!signal_pending (current)) //signal_pending 函数返回不为0表示有信号处理
{
printk("signal_pending\n");
}
while(1)
{
//kthread_should_stop判断线程是否应该结束,返回true表示结束,false表示不结束
if(kthread_should_stop())
{
break;
}
}
return 0;
}
struct task_struct *thread_task;//定义一个task_struct结构体
使用kread_create(main_thread, ...)//创建内核线程函数