Process Descriptor and Task Structure
Task list
The kernel stores the list of processes in a circularly doubly linked list called a task list
Each element in the task list is called a process descriptor, and it has a struct of type task_struct
(see <linux/sched.h>
)
Allocating the Process Descriptor
The task_struct
of the process descriptor is allocated via the slab allocator
Prior v2.6 kernels, task_struct
was stored at the end of the kernel stack of each process
Now, with task_struct
dynamically created via the slab allocator, a new struct thread_info
lies at the end of the kernel stack instead
Within the thread_info
struct has a member called task
, which points the actual task_structure
Storing PID
The kernel identifies a process by using a unique process identification called a PID
represented by pid_t
Default value of PID
is 32,768, which can be modified in <linux/threads.h>
. The value of the current max PID
can be found in /proc/sys/kernel/pid_max
Looking up for process descriptor of the current task
To access the process descriptor of the current task, a macro called current
can be used
current_thread_info()->task