2

From my kernel module I want to iterate over task list and do some sleepy operation for all the processes for which my task->flag is set. I know by holding read_lock(tasklist_lock)/rcu_read_lock, I should not be doing any sleepy operation. SO I have coded like below :

1.Take the read lock
2.Iterate over task (for_each_process)
3.If my flag is set I unlock the tasklist_lock and get_task_struct
4.Then I perform the sleepy operation
5.Put_task_struct
6.Again Take read_lock(&tasklist_lock);
7.Loop continues

read_lock(&tasklist_lock);

    for_each_process(c) {

            if (c->my_flag) {

            read_unlock(&tasklist_lock);

                    get_task_struct(c);

                         ...

                         Do some sleepy_operation()

                         ...

                    put_task_struct(c);

                    read_lock(&tasklist_lock);

            }
    }

Please let me know if my approach is correct

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.