On 2012-04-12 18:16:56 (+0800), harryxiyou <[email protected]> wrote:
> Hi greg,
> 
>     I write a module for inserting a PCB or delete a PCB to kernel's
> PCB tree, but when i run it something wrong happens to me like following.
> My environment is "Linux 10 2.6.35-22-generic #33-Ubuntu SMP Sun Sep
> 19 20:34:50 UTC 2010 i686 GNU/Linux"
> 
>       
>       printk("Search for insert task-------->\n");
>       task = &init_task;
>       list_for_each(pos, &task->tasks) {
>               p = list_entry(pos, struct task_struct, tasks);
>               count++;
>               if (0 == p->pid) {
>                       rm_task(p);
>               }
>               printk("pid: %d, state: %ld, comm: %s\n", p->pid, p->state, 
> p->comm);
>       }
>
You're iterating over the tasks list without locking it.

What do you think happens if someone else comes along and modifies it
while you're reading it?

Try to take the tasklist_lock.

Regards,
Kristof


_______________________________________________
Kernelnewbies mailing list
[email protected]
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to