Is there any policy in Linux as to the recycling of used PIDs ? I mean, if a PId has been used, how much later will it be used again ?
As long as a process is dead and has been waited for (by its parent, or the sub child reaper or init if the parent is dead), its pid can be reused. Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.
Since PID is an unique identifier for a process, there's no way to have two distinct process with the same PID. Unless the processes are running in a separate PID namespaces (and thus can have the same PID).
Most PIDs have a unique identifier which is linked to the current address of the metadata or content. Unlike URLs, PIDs are often provided by services that allow you to update the location of the object so that the identifierconsistently points to the right place without breaking.
PID in Linux and Windows are unique to that process. PIDs will never change.
As new processes fork in, PIDs will increase to a system-dependent limit and then wrap around. The kernel will not reuse a PID before this wrap-around happens.
The limit (maximum number of pids) is /proc/sys/kernel/pid_max
. The manual says:
/proc/sys/kernel/pid_max
(since Linux 2.5.34)This file specifies the value at which PIDs wrap around (i.e., the value in this file is one greater than the maximum PID). The default value for this file,
32768
, results in the same range of PIDs as on earlier kernels
https://superuser.com/questions/135007/how-are-pids-generated
This should answer your question - it appears it will recycle PIDs when it runs out, skipping the ones that are still assigned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With