Linux PID 回收

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11323410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 10:49:59  来源:igfitidea点击:

Linux PID recycling

linuxpidrecycle

提问by Cygnus

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 ?

Linux 中是否有关于回收使用过的 PID 的任何政策?我的意思是,如果一个 PId 已被使用,它会在多长时间后再次使用?

采纳答案by cnicutar

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.

随着新进程的出现,PID 将增加到依赖于系统的限制,然后回绕。在这种环绕发生之前,内核不会重用 PID。

The limit (maximum number of pids) is /proc/sys/kernel/pid_max. The manualsays:

限制(pid 的最大数量)是/proc/sys/kernel/pid_max. 手册上说:

/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

/proc/sys/kernel/pid_max(从 Linux 2.5.34 开始)

此文件指定PID 环绕的值(即,此文件中的值比最大 PID 大 1)。此文件的默认值32768导致与早期内核相同的 PID 范围

回答by Osmium USA

https://superuser.com/questions/135007/how-are-pids-generated

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.

这应该可以回答您的问题 - 看起来它会在用完时回收 PID,跳过仍然分配的那些。