forked from cirosantilli/linux-kernel-module-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.c
39 lines (32 loc) · 745 Bytes
/
schedule.c
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
/* https://cirosantilli.com/linux-kernel-module-cheat#schedule */
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <uapi/linux/stat.h> /* S_IRUSR | S_IWUSR */
static int do_schedule = 1;
module_param_named(schedule, do_schedule, int, S_IRUSR | S_IWUSR);
static struct task_struct *kthread;
static int work_func(void *data)
{
unsigned int i = 0;
while (!kthread_should_stop()) {
pr_info("%u\n", i);
i++;
if (do_schedule)
schedule();
}
return 0;
}
static int myinit(void)
{
kthread = kthread_create(work_func, NULL, "mykthread");
wake_up_process(kthread);
return 0;
}
static void myexit(void)
{
kthread_stop(kthread);
}
module_init(myinit)
module_exit(myexit)
MODULE_LICENSE("GPL");