Created
September 20, 2013 03:47
-
-
Save gauthamkantharaju/6633058 to your computer and use it in GitHub Desktop.
Kernel thread usage in device driver
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/init.h> | |
#include <linux/fs.h> | |
#include <linux/slab.h> | |
#include <linux/kthread.h> | |
#include <linux/sched.h> | |
#include <linux/delay.h> | |
MODULE_LICENSE("GPL"); | |
static struct task_struct *ts; | |
int kthread_func (void * data) | |
{ | |
while( 1 ) | |
{ | |
printk("Inside kernel thread \n"); | |
if( kthread_should_stop() ) | |
break; | |
} | |
do_exit(0); | |
} | |
static int __init thread_init(void) | |
{ | |
ts = kthread_run(kthread_func, NULL, "kthread"); | |
return 0; | |
} | |
static void __exit thread_exit(void) | |
{ | |
printk("Stopping thread and exiting !!! \n"); | |
kthread_stop(ts); | |
} | |
module_init(thread_init); | |
module_exit(thread_exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment