如何获取属于某个进程的打开的句柄数? [英] How to get count of opened handles that belongs to a certain process?
本文介绍了如何获取属于某个进程的打开的句柄数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以使用程序 Process Explorer 来查看有多少个句柄正在运行应用程序有. Delphi代码有没有办法获取这个数字?我对跟踪应用程序本身的数量感兴趣;找不到Process Explorer正在执行的其他应用程序使用的句柄数.
You can use the program Process Explorer to see how many handles running applications have. Is there a way with Delphi code to get this number? I am interested in tracking the number for the application itself; not to find the number of handles used by other applications as Process Explorer is doing.
我的目的是让应用程序跟踪/检测可能的资源泄漏.
My intention is for the application to track/detect possible resource leaks.
推荐答案
Use the GetProcessHandleCount
function. This API function is in recent versions of Delphi imported by the Winapi.Windows unit (so you can omit the presented one):
function GetProcessHandleCount(hProcess: THandle; var pdwHandleCount: DWORD): BOOL; stdcall;
external 'kernel32.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
HandleCount: DWORD;
begin
if GetProcessHandleCount(GetCurrentProcess, HandleCount) then
ShowMessage('Handle count: ' + IntToStr(HandleCount));
end;
这篇关于如何获取属于某个进程的打开的句柄数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文