You will recall, in our sample run of the preceding countem.sh script (in the Organizing processes, threads, and their stacks – user and kernel space section), we found that there are a total of 1,234 threads (both user and kernel) alive on the system. This implies that there will be a total of 1,234 task structure objects in the kernel memory.
They need to be organized in a way that the kernel can easily access them as and when required. Thus, all the task structure objects in kernel memory are chained up on a circular doubly linked list called the task list. This kind of organization is required in order for various kernel code paths to iterate over them (commonly the procfs code, among others). Even so, think on this: when a process or thread is running kernel code (in process context), how can it find out which task_struct belongs to it among the perhaps hundreds or thousands that...