问题中提到,通过提问者的测试(Ubuntu18.04操作系统下),Python脚本实现的分配进行pid脚本,渠道系统自动分配给进程的最大pid值是131070,这是一个并不特殊的值。(通常可以想到的上限会是与二进制数字相关,例如1024,65536等等)。
很高兴,看到还是有很多人在坚持知乎的本来精神,先问是不是,再问为什么。
Linux 内核的进程 PID 最大值并非 131070,而是 32768 (32 位系统)和 2 的 22 次方(64 位系统)。这是Linux手册中明确给出的说明:
/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). PIDs greater than this value are not allocated; thus, the value in this file also acts as a system-wide limit on the total number of processes and threads. The default value for this file, 32768, results in the same range of PIDs as on earlier kernels. On 32-bit platforms,