linux kernel - How do waitpid and ptrace work together? -
going through source code of linux 4.12, can't wrap head around below code when task being ptraced.
do_wait()
will call
ptrace_do_wait(wo, tsk)
which call
wait_consider_task
for every thread tracing on. in turn call
wait_task_stopped
which find pid [pid = task_pid_vnr(p);]
waitpid return, great.
but calls
put_task_struct(p);
which free task structure. if happens, how debugger wait on process/task again? entry added again somewhere, , if where?
can 1 explain flow me? thanks.
what mean "put_task_struct frees structure"? familiar reference counting? did see matching get_task_struct?
let's have @ code:
get_task_struct(p);
refcount incremented
pid = task_pid_vnr(p); why = ptrace ? cld_trapped : cld_stopped; read_unlock(&tasklist_lock);
the list of tasks unlocked. in principle can wait() on thread rid of structure due increased refcount
sched_annotate_sleep(); if (wo->wo_rusage) getrusage(p, rusage_both, wo->wo_rusage); put_task_struct(p);
... , refcount decremented. if last ref, object freed. otherwise nothing happens.
Comments
Post a Comment