创建内核线程的方法 kthread_run,示例如下:
//线程执行函数
static int kthread_loop(void* param)
{
int loopVal = 0;
printk(KERN_INFO "start loop\n");
while (1)
{
//加入退出判断
}
printk(KERN_INFO "stop loop\n");
return 0;
}
//创建线程并唤新线程
struct task_struct *loop_task = kthread_run(kthread_loop, NULL, "loop");
if (IS_ERR(loop_task))
{
printk(KERN_ERR "print loop: unable to create kernel thread: %ld\n",
PTR_ERR(loop_task));
}
//如果有兴趣还可以将其绑定到指定的CPU上
set_cpus_allowed(loop_task, cpumask_of_cpu(15));
阅读(2701) | 评论(1) | 转发(0) |