Iterating over the kernel’s task lists
As mentioned earlier, all the task structures are organized in kernel memory in a linked list called the task list (allowing them to be iterated over). The list data structure has evolved to become the very commonly used circular doubly linked list. In fact, the core kernel code to work with these lists has been factored out into a header called list.h
; it’s well-known and expected to be used for any list-based work.
The include/linux/types.h:list_head
data structure forms the essential doubly linked circular list; as expected, it consists of two pointers, one to the prev
member on the list and one to the next
member:
struct list_head {
struct list_head *next, *prev;
};
You can easily iterate over various lists concerned with tasks via conveniently provided macros in the include/linux/sched/signal.h
header file for versions >= 4.11; note that for kernels 4.10 and older, the macros are in include/linux/sched...