#include <linux/module.h>
#include <linux/init.h>
#include <linux/atomic.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/delay.h>
static struct task_struct *task;
static int thread_fun(void *unused)
{
int i = 0;
while (!kthread_should_stop()) {
pr_info("thread_fun stop:%d\n", kthread_should_stop());
ssleep(3);
i++;
if (i++ > 50) {
break;
}
}
return 0;
}
static __init int test_init(void)
{
pr_info("test init\n");
task = kthread_run(thread_fun, NULL, "test");
return 0;
}
static __exit void test_exit(void)
{
pr_info("test exit enter\n");
if (task) {
pr_info("task is live\n");
kthread_stop(task);
task = NULL;
}
pr_info("test exit end\n");
}
module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
内核线程
最新推荐文章于 2024-01-11 14:45:28 发布