Kernel: how to find all threads from task_struct process?

Given the structure of the task for a process or thread, what is the idiom of iterating over all other threads belonging to the same process?

+3
source share
1 answer

Linux does not distinguish between a process (task) and a thread. The library calls fork () and pthread_create () uses the same clone () system call. The difference between fork () and pthread_create () is the bitmask passed to clone (). This bitmask describes which resources (memory, files, file systems, signal handler, ...). See Man clone (2) for more details.

, -, , clone(), , . , clone(), CLONE_THREAD . * while_each_thread * include sched.h. :

struct task_struct *me = current();
struct task_stuct *t = me;
do {
    whatever(t);
}while_each_thread(me, t);
+13

Source: https://habr.com/ru/post/1568460/


All Articles