#include <stdio.h>
#include <linux/sched.h>
static struct task_struct *test_task = NULL;
static int test_monitor_process(void *data)
{
while(!kthread_should_stop())
{
printf("hhhh\n");
}
return 0;
}
static int __init thread_test_init(void)
{
int ret = 0;
printk("modprobe thread");
test_task = kthread_create(test_monitor_process, 0, "test_monitor");
if(!IS_ERR(test_task))
{
struct sched_param param = {.sched_priority = 91,};
sched_setscheduler(test_task, SCHED_FIFO, ¶m);
wake_up_process(test_task);
printk("start test monitor thread successfully!\n");
}
else
{
printk("start test monitor thread failed!\n");
ret = -ENOMEM;
}
return ret;
}
static void __exit thread_test_exit(void)
{
printk("exit thread mod");
kthread_stop(test_task);
}
module_init(thread_test_init);
module_exit(thread_test_exit);
kthread_create 创建
sched_setscheduler 设置优先级
wake_up_process 拉起
kthread_stop 停止