On Wed, Feb 20, 2013 at 11:59 AM, Srinivas Ganji < srinivasganji.kernel@gmail.com> wrote:
On Tue, Feb 19, 2013 at 5:02 PM, Kevin Wilson <wkevils@gmail.com> wrote:
Hi,
Thanks about the info about ps. This raises two new questions: 1) The following code is a very basic kernel module (based on my previous code, removing somethings). I do not understand something: I call /* sleep for a millisecond */ msleep(1); printk("calling do_exit\n"); msleep(60000);
In my understanding, after 1 millisecond, it should have been available to the scheduler, and after returning to the line after msleep(1), it should print "calling do_exit". However, I see no such log message. Any ideas why ? can something be added to enable this ?
2)How can I create a kernel thread so that it will be in TASK_INTERRUPTIBLE state ? there must be a way, since I see many kernel threads where ps shows "S" in the status coumn.
struct task_struct *task;
int thread_function(void *data) { int exit_sig = SIGKILL;
printk("in %s\n",__func__); /* sleep for a millisecond */ msleep(1); printk("calling do_exit\n"); msleep(60000); do_exit(exit_sig);
return 0; }
static int kernel_init(void) { printk("in kernel_init\n"); task = kthread_create(thread_function,NULL,"MY_KERNEL_THREAD"); return 0; }
static void kernel_exit(void) { printk("in kernel_exit\n"); kthread_stop(task); }
module_init(kernel_init); module_exit(kernel_exit);
rgs Kevin
After creating the kernel thread, you can use wake_up_process(task) call which will run your thread function.
Generally, when we create a kernel thread using kthread_create,
the process is created in an unrunnable state. It will not start running until explicitly woken up via wake_up_process(). The kthread_create() followed by wake_up_process() is done by a single call kthread_run(). I hope this helps you. Regards Srinivas G.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies