-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkthread.c
More file actions
45 lines (37 loc) · 887 Bytes
/
kthread.c
File metadata and controls
45 lines (37 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/jiffies.h>
#include <linux/delay.h>
static struct task_struct *task = NULL;
static int kthread_sample(void *data)
{
do
{
printk("kthread sample running... \n");
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(msecs_to_jiffies(1000));
} while (!kthread_should_stop());
return 0;
}
static int __init kthread_sample_init(void)
{
task = kthread_run(kthread_sample, NULL, "kthread_sample");
if (IS_ERR(task))
return -EBUSY;
return 0;
}
static void __exit kthread_sample_exit(void)
{
if (task != NULL && (!IS_ERR(task)))
{
kthread_stop(task);
}
}
module_init(kthread_sample_init);
module_exit(kthread_sample_exit);
MODULE_DESCRIPTION("kthread Sample Driver");
MODULE_AUTHOR("Mr.Chowe");
MODULE_LICENSE("GPL v3");