Skip to contentSkip to conversation

get_task_struct()

DISCUSSION Fabiano Ramos 2 participants 2 messages Apr 17, 2004

lore
Share & tools
lore
#0 lore raw

Dear All,

Inside sys_ptrace, the function get_task_struct is invoked after retrieving the child's task srtuct pointer. Why is it done? I have tracked down the code and noticed that it is in fact an increment on the (page?) counter. Can you help me understand it?

Is it necessary to call free_task_struct whenever its get counterpart is called?

** arch/i386/kernel/ptrace.c

Quoted 5 lines

read_lock(&tasklist_lock);
child = find_task_by_pid(pid);
if (child)

             get_task_struct(child);

read_unlock(&tasklist_lock);

Thanks in advance,
Fabiano

#1 lore raw
Quoted 4 lines · Fabiano Ramos

Inside sys_ptrace, the function get_task_struct is invoked after retrieving the child's task srtuct pointer. Why is it done? I have tracked down the code and noticed that it is in fact an increment on the (page?) counter. Can you help me understand it?

Think of get_task_struct(foo) as a reference count on foo's task structure. So long as the reference count is elevated, foo's task structure cannot be deallocated.

get_task_struct() is called here because sys_ptrace() needs to ensure that the child's task structure does not go away out from under this function, but we do not want to hold the tasklist_lock.

Quoted 2 lines

Is it necessary to call free_task_struct whenever its get counterpart is called?

Yes, although it is called "put_task_struct()". It is called at the end of this function.

Robert Love