I wrote the following code to create a kernel thread:
#include
#include
#include
#include
I hope the below program resolves your problem.... thumbs up :-)
`#include
#include
#include
#include
#include`
struct task_struct *task;
int data;
int ret;
int thread_function(void *data)
{
int var;
var = 10;
printk(KERN_INFO "IN THREAD FUNCTION");
while(!kthread_should_stop()){
schedule();
}
/*do_exit(1);*/
return var;
}
static int kernel_init(void)
{
data = 20;
printk(KERN_INFO"--------------------------------------------");
/*task = kthread_create(&thread_function,(void *)data,"pradeep");*/
task = kthread_run(&thread_function,(void *)data,"pradeep");
printk(KERN_INFO"Kernel Thread : %s\n",task->comm);
return 0;
}
static void kernel_exit(void)
{
kthread_stop(task);
}
module_init(kernel_init);
module_exit(kernel_exit);
MODULE_AUTHOR("SHRQ");
MODULE_LICENSE("GPL");