On Thu, Jul 07, 2005 at 13:22:42 +0530, Sanjay Kumar, Noida wrote:
> One possible way to achieve the above task can be as follows.
> I used kernel linux-2.6.8
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/wait.h>
> #include <linux/sched.h>
> #include <linux/list.h>
>
> static struct task_struct *my_task;
> static DECLARE_WAIT_QUEUE_HEAD(my_queue);
> wait_queue wait;
>
> static int pid=1; //pass process id to module as parameter
> MODULE_PARM(pid, "i");
>
> int init_module()
> {
> my_task=find_task_by_pid(pid);
> DECLARE_WAITQUEUE(wait1, my_task);
> wait=wait1;
> my_task->state = TASK_INTERRUPTIBLE;
You should use the set_task_state macro here.
Note, that this no longer works for current in 2.6
(it did in 2.4, before the preemption came).
> init_waitqueue_entry(&wait, my_task);
> add_wait_queue(&my_queue, &wait);
> return 0;
> }
> void cleanup_module()
> {
> printk("exiting\n");
> wake_up_interruptible(&my_queue);
> my_task->state = TASK_RUNNING;
> remove_wait_queue(&my_queue, &wait);
> }
> MODULE_LICENSE("GPL");
> ========================
>
> It worked for me perfectly.
> Kindly let me know if I am missing something.
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature