I would like to know how many file descriptors have I opened in my C++ application. Can this be done using Windows API function?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can ask each handle in the process using GetFileType.
DWORD type_char = 0,
type_disk = 0,
type_pipe = 0,
type_remote = 0,
type_unknown = 0,
handles_count = 0;
GetProcessHandleCount(GetCurrentProcess(), &handles_count);
handles_count *= 4;
for (DWORD handle = 0x4; handle < handles_count; handle += 4) {
switch (GetFileType((HANDLE)handle)){
case FILE_TYPE_CHAR:
type_char++;
break;
case FILE_TYPE_DISK:
type_disk++;
break;
case FILE_TYPE_PIPE:
type_pipe++;
break;
case FILE_TYPE_REMOTE:
type_remote++;
break;
case FILE_TYPE_UNKNOWN:
if (GetLastError() == NO_ERROR) type_unknown++;
break;
}
}
回答2:
If you are after checking open handles then you can the Handle utility from SysInternals.