最近一个服务程序在长时间运行中句柄不断上涨,最高达到了40000多个,停止服务后也不会下降,所以造成泄漏的可能性很大;
虽然尚未造成程序使用问题,还是需要解决;
通过debug diagnose可以大概定位了具体位置
下面是关于进程句柄的一些细节。
1:一个windows进程最多有1600万个句柄,这是理论上的;
2:句柄表是从系统的换页内存池中分配的,所以在未达到1600万的数量前,很可能系统换页内存池耗尽了
3:可以通过 sysinternals Testlimit 的工具来检测当前系统最大的句柄数目。
摘自"Windows Internals Fifth Edition "
An object handle is an index into a process-specific handle table, pointed to by the executive
process (EPROCESS) block (described in Chapter 5). The first handle index is 4, the second
8, and so on. A process’s handle table contains pointers to all the objects that the process
has opened a handle to. Handle tables are implemented as a three-level scheme, similar
to the way that the x86 memory management unit implements virtual-to-physical address
152 Windows Internals, Fifth Edition
translation, giving a maximum of more than
16,000,000 handles per process
The test program Testlimit from Sysinternals has an option to open handles to an object
until it cannot open any more handles. You can use this to see how many handles can
be created in a single process on your system. Because handle tables are allocated from
paged pool, you might run out of paged pool before you hit the maximum number of
handles that can be created in a single process. To see how many handles you can create
on your system, follow these steps:
1. Download the Testlimit .zip file from www.microsoft.com/technet/ sysinternals, and
unzip it into a directory.
Run Process Explorer, and then click View and then System Information. Notice
the current and maximum size of paged pool. (To display the maximum pool size
values, Process Explorer must be configured properly to access the symbols for
the kernel image, Ntoskrnl.exe.) Leave this system information display running so
that you can see pool utilization when you run the Testlimit program.
3. Open a command prompt.
4. Run the Testlimit program with the -h switch (do this by typing testlimit –h).
When Testlimit fails to open a new handle, it will display the total number of
handles it was able to create. If the number is less than approximately 16 million,
you are probably running out of paged pool before hitting the theoretical perprocess
handle limit.
5. Close the Command Prompt window; doing this will kill the Testlimit process, thus
closing all the open handles.