Operating system-the internal structure of the Linux process implementation

Source: Internet
Author: User

Entering several fields in the process descriptor represents a parent-child relationship and a sibling relationship between processes.


Figure 3-4 shows the kinship between a set of processes.



Table 3-4: Process descriptor fields to establish non-kinship



In some cases, the kernel must be able to have a process descriptor pointer from the PID of the process, scanning the process list sequentially and checking the PID field of the process descriptor is feasible but rather inefficient . To speed up the search, 4 hash lists were introduced. 4 hash lists are required because the process descriptor contains fields that represent different types of PID, and each type of PID requires its own hash table.



The hash function does not always ensure that the PID corresponds to the table's index one by one. Two different PID hashes (hashes) to the same table index are called collisions (colliding). Linux uses a linked list to handle conflicting PID: Each table entry is a doubly linked list of conflicting process descriptors. Figure 3-5 shows a PID hash table with two linked lists. The process number (PID) is 2890 and 29384 of the two processes hash to the NO. 200 element of this table, while the process number (PID) for the process of 29385 is hashed to the 1466th element of the table.


The Liefabi with a linked list is superior to linear conversion from PID to table index.

PID Hash list The main data structure is 4 PID structure of the array, it in the Process Descriptor PID field, table 3-6 shows the PID structure of the field.



Figure 3-6 shows an example of a Pidtype_tgid type hash list. The second element of the Pid_hash array holds the address of the hash table, which is an array of hlist_head structures representing the head of the linked list. Hash table 71st is the list of start journeys, there are two process descriptors with PID numbers 246 and 4351 (double arrow lines represent a pair of forward and backward pointers). The PID value is stored in the Nr field of the PID structure, and the PID structure is in the process descriptor, (incidentally, because the number of the process group is the same as the PID of its creator, these PID values also exist in the Process Descriptor PID field.) We consider the PID linked list of thread group 4351: The Pid_list field of the process descriptor in the hash table holds the head of the linked list, and the pointer to the previous element and the next element in each PID list also holds the Pid_list field of each linked list element.




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Operating system-the internal structure of the Linux process implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.