Windows 7是否回收进程ID(PID)编号? [英] Does Windows 7 recycle process id (PID) numbers?

查看:219
本文介绍了Windows 7是否回收进程ID(PID)编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小的测试程序,可以跟踪PID的创建和关闭情况. 我正在调查我的程序已发现的问题,并想问您有关此问题的信息 为了对发生的事情有一个更好的了解.

I have this little test program that tracks PID's as they are created and shut down. I am investigating a problem that my program has found and would like to ask you about this in order to have a better idea on what's going on.

启动Windows进程时,它将获得PID,但是当进程关闭时,将获得PID 退休(例如篮球明星的球衣号码),或者有可能完全换个新的 不相关,要在已发布的PID下创建流程?

When a windows process is started, it gets a PID but when the process is shut down, does the PID become retired (like a star basketballer's jersey number) or is it possible for a new, entirely unrelated, process to be created under that released PID?

谢谢

推荐答案

是的,系统可能会回收进程ID.一旦关闭了该过程的最后一个句柄,便可以使用它们.

Yes, process IDs may be recycled by the system. They become available for this as soon as the last handle to the process has been closed.

Raymond Chen在这里讨论了此问题:进程ID何时可用可以重复使用?

Raymond Chen discussed this matter here: When does a process ID become available for reuse?

进程ID是与该进程对象相关联的值,并且作为 只要过程对象仍然存在,其过程也将 ID.只要流程仍在运行,流程对象就会保留 (该过程隐式保留对自身的引用)或 仍然有人可以处理过程对象.

The process ID is a value associated with the process object, and as long as the process object is still around, so too will its process ID. The process object remains as long as the process is still running (the process implicitly retains a reference to itself) or as long as somebody still has a handle to the process object.

如果您考虑一下,这是有道理的,因为只要有 仍然是该过程的句柄,有人可以调用WaitForSingleObject 等待进程退出,或者他们可以调用GetExitCodeProcess 检索退出代码,并且必须存储该退出代码 某个地方以便以后检索.

If you think about it, this makes sense, because as long as there is still a handle to the process, somebody can call WaitForSingleObject to wait for the process to exit, or they can call GetExitCodeProcess to retrieve the exit code, and that exit code has to be stored somewhere for later retrieval.

当所有句柄都关闭时,内核知道没有人 会问该进程是否仍在运行或退出了什么 代码是(因为您需要一个句柄来问那些问题).在哪 指出过程对象可以被销毁,这又会销毁 进程ID.

When all handles are closed, then the kernel knows that nobody is going to ask whether the process is still running or what its exit code is (because you need a handle to ask those questions). At which point the process object can be destroyed, which in turn destroys the process ID.

这篇关于Windows 7是否回收进程ID(PID)编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆