Generating Unique PIDs
In addition to managing PIDs, the kernel is also responsible for providing a mechanism to generate unique PIDs that have not yet been assigned. In this case, the differences between the various PID types can be ignored because unique numbers need only be generated for PIDs in the classical Unix sense. All other identifiers can be derived from the PID, as we will see when discussing fork and clone below. In the sections that follow, the term PID once again refers to the classical Unix process identifier (pidtype_pid).
To keep track of which PIDs have been allocated and which are still free, the kernel uses a large bitmap in which each PID is identified by a bit. The value of the PID is obtained from the position of the bit in the bitmap.
Allocating a free PID is then restricted essentially to looking for the first bit in the bitmap whose value is 0; this bit is then set to 1. Conversely, freeing a PID can be implemented by "toggling" the corresponding bit from 1 to 0. These operations are implemented using
Continue reading here: Kernelpidc
Was this article helpful?