Skip to content

Instantly share code, notes, and snippets.

@gauthamkantharaju
Created September 20, 2013 03:47
Show Gist options
  • Save gauthamkantharaju/6633058 to your computer and use it in GitHub Desktop.
Save gauthamkantharaju/6633058 to your computer and use it in GitHub Desktop.
Kernel thread usage in device driver
#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