Each process in a Linux system is identified by a process ID, a process descriptor that corresponds to a task_struct structure in the kernel, and the task_struct of all processes in the system are linked through a chain table, and in the kernel it is often necessary to get the process descriptor through the process ID. The simplest method can be obtained by traversing the Task_struct list and comparing the value of the ID, but this is too inefficient, especially if there are many processes running in the system.
The Linux kernel solves this problem by using a PID hash list , which can quickly get to the process descriptor through the process ID .
The PID hash list contains 4 tables because the process descriptor contains fields that represent different types of PID, and each type of PID requires its own hash table.
enum pid_type{ pidtype_pid, // pid of process pid / thread Group lead process // Process Group lead process PID pidtype_sid,// PID pidtype_max // type number of Session lead process };
View/proc/pid/status to see the current status of some processes:
[Email Protected]:/proc/19280/task $ cat 19282/status Name:gcstate:s (sleeping) Tgid:19280Pid:19282PPid:17974Tracerpid:0Uid:10043 10043 10043 10043Gid:10043 10043 10043 10043fdsize:256Groups:1006 1007 1015 1028 3001 3002 3003Vmpeak:483560kbvmsize:481500Kbvmlck:0Kbvmpin:0KBVMHWM:44940Kbvmrss:29684Kbvmdata:24848KBVMSTK:136Kbvmexe:8Kbvmlib:29096Kbvmpte:160Kbvmswap:0kbthreads:19Sigq:0/5987SIGPND:0000000000000000SHDPND:0000000000000000sigblk:0000000000001204sigign:0000000000000000Sigcgt:00000002000094e8capinh:0000000000000000CAPPRM:0000000000000000Capeff:0000000000000000capbnd:ffffffffffffffffcpus_allowed:3cpus_allowed_list:0-1voluntary_ctxt_switches:5nonvoluntary_ctxt_switches:33
[Linux] Linux Process PID Hash table