Created
May 12, 2019 09:18
-
-
Save md-jamal/998a6f263acce26883c54b0e9a7ec58f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <linux/module.h> | |
| #include <linux/kernel.h> | |
| #include <linux/init.h> | |
| #include <linux/smp.h> | |
| #include <linux/sched.h> | |
| #include <linux/kthread.h> | |
| #include <linux/delay.h> | |
| MODULE_LICENSE("GPL"); | |
| static struct task_struct *my_task = NULL; | |
| static int my_kthread(void *data) { | |
| char *str = (char *)data; | |
| pr_info("my kthread data: %s\n", str); | |
| pr_info("my kthread smp_processor_id %d\n", smp_processor_id()); | |
| while(!kthread_should_stop()) { | |
| msleep(5000); | |
| pr_info("my kthread: living. smp_processor_id %d\n", smp_processor_id()); | |
| pr_info("=========================================\n"); | |
| } | |
| pr_info("my kthread: stop\n"); | |
| return 0; | |
| } | |
| static int __init my_init(void) | |
| { | |
| pr_info("my init.\n"); | |
| pr_info("smp_processor_id %d\n", smp_processor_id()); | |
| my_task = kthread_run(my_kthread, "hello my kthread", "mykthread-%s", "test"); | |
| pr_info("my init finish.\n"); | |
| pr_info("=========================================\n"); | |
| return 0; | |
| } | |
| static void __exit my_exit(void) | |
| { | |
| pr_info("my exit.\n"); | |
| pr_info("smp_processor_id %d\n", smp_processor_id()); | |
| if (my_task) { | |
| pr_info("stop kthread\n"); | |
| kthread_stop(my_task); | |
| } | |
| pr_info("my exit finish.\n"); | |
| pr_info("=========================================\n"); | |
| } | |
| module_init(my_init); | |
| module_exit(my_exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment