struct pid * fastcall find_pid_ns(int nr, struct pid_namespace *ns)
Instances of struct upid are kept on the hash, but since these are directly contained in struct pid, the kernel can infer the desired information using the container_of mechanism (see Appendix C).
2. pid_task extracts the first task_struct instance that is queued on the list pid->tasks[type].
These two steps are performed by the auxiliary function find_task_by_pid)_type_ns: kernel/pid.c struct task_struct *find_task_by_pid_type_ns(int type, int nr, struct pid_namespace *ns)
5 For this purpose, the kernel uses multiplicative hashing with a prime number that is in a golden ratio to the largest number that can be represented in a machine word. For details, refer to [Knu97].
Some simpler auxiliary functions build on the most general find_task_by_pid_type_ns:
□ find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns) finds a task_struct instance given a numerical PID and the namespace of the task.
□ find_task_by_vpid(pid_t vnr) finds a task by its local numerical PID.
□ find_task_by_pid(pid_t nr) finds a task by its global numerical PID.
find_task_by_pid is required at many points in the kernel sources because a large number of process-specific operations (e.g., sending a signal using kill) identify their target process by means of its PID.
Continue reading here: Generating Unique PIDs
Was this article helpful?