This is Linux! There are no secrets here! Have a peek at the Linux source-code in
/usr/src/linux/kernel/pid.c and see for yourself!
It's probably more complicated than you expected ...
Logically speaking, a PID (process ID) is simply that: an
identifier. Maybe in the earliest days it was some kind of physical index into a table, but I doubt it.
What the Linux system needs, and what
pid.c provides, is:
- PIDs are positive integers greater than 1; PID #1 is reserved. Other than that, the actual value is completely meaningless and arbitrary. Very large gaps in the numbering sequence are to be expected.
- PID-values will not be re-used for a very long time. A value will never be reassigned if there are any "dangling" references to it, even if the process in question no longer exists.
- No two simultaneously-existing processes will ever exist with the same PID.
- New unique PIDs can be assigned almost-instantaneously, even on multiprocessor machines.