流程结束后,流程句柄将如何处理? [英] What happens to a process handle once the process was ended?

查看:141
本文介绍了流程结束后,流程句柄将如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一些已停止(已终止或已终止)的Windows进程的句柄:

if I have a handle to some windows process which has stopped (killed or just ended):

  1. 该句柄(或更好的是它后面的内存)是否可以重新用于其他进程?
  2. 或者从现在开始,例如GetExitCodeProcess()会永远获得正确的结果吗?

如果1.为true:GetExitCodeProcess()的工作时间有多长?
如果是2,则是真的:这是否意味着因为我创建了越来越多的句柄(并且OS为它们保留了内存),所以我可以通过启动/终止新进程来关闭OS?

If 1. is true: How "long" would GetExitCodeProcess() work?
If 2. is true: Wouldn't that mean that I can bring down the OS with starting/killing new processes, since I create more and more handles (and the OS reserves memory for them)?

我对手柄的概念有些困惑.

I'm a bit confused about the concept of handles.

提前谢谢!

推荐答案

句柄间接指向内核对象.只要有打开的手柄,该对象就会保持活动状态.

The handle indirectly points to an kernel object. As long as there are open handles, the object will be kept alive.

该句柄(或更好的是它后面的内存)是否可以重新用于其他进程?

Will the handle (or better the memory behind it) be re-used for another process?

句柄(或实现它的数字)的数值可能会被重用,但这并不意味着它将始终指向同一事物.就像进程ID一样.

The numeric value of the handle (or however it is implemented) might get reused, but that doesn't mean it'll always point to the same thing. Just like process IDs.

或者从现在开始,例如GetExitCodeProcess()会永远获得正确的结果吗?

Or will GetExitCodeProcess() for example get the correct result forever from now on?

不.关闭流程的所有句柄后,流程对象(及其退出代码)将被释放.请注意,正在运行的进程对其自身具有隐式句柄.不过,只要需要,您也可以握住打开的手柄.

No. When all handles to the process are closed, the process object is freed (along with its exit code). Note that running process holds an implicit handle to itself. You can hold an open handle, though, as long as you need it.

如果2是正确的:那不是因为我创建了越来越多的句柄(并且OS为它们保留了内存),我就可以通过启动/终止新进程来关闭OS了吗?

If 2. is true: Wouldn't that mean that I can bring down the OS with starting/killing new processes, since I create more and more handles (and the OS reserves memory for them)?

有很多方法可以使系统饥饿.它要么开始大量交换,要么就无法在某个时候生成新进程.

There are many ways to starve the system. It will either start heavily swapping or just fail to spawn a new process at some point.

这篇关于流程结束后,流程句柄将如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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