什么执行堆栈/.NET AppDomain 保存文件句柄?
我有 .NET 可执行文件,它在单独的 AppDomains 中托管插件。 有时,在应用程序使用过程中,此插件之一会锁定文件并阻止其移动或删除。
我需要找出谁持有文件句柄?
问题是间歇性的并且难以重现。有5个插件。 禁止插件访问此文件或杀死句柄(如 Unlocker 那样)并不是解决方案。
我尝试过:
首先,Sysinternals - 但它仅显示保存具有指定名称的文件的进程。
其次,正如有关 WinDbg 的文章和文档中所述,我可以使用 !process 和 !handle,但接下来:
0:001> !process
No export process found
0:001> !handle 314 ff 123
Unknown type '123
我可以使用带有较少参数的 !handle,但我的版本(出于未知原因)甚至不显示文件名,如 < a href="http://www.codeproject.com/Articles/6988/Debug-Tutorial-Part-5-Handle-Leaks" rel="nofollow">调试教程第 5 部分:句柄泄漏。我的可执行文件引用了 100 个文件。 我想深入研究 WinDbg,但由于某种原因,它是从 Windows 7 SDK 安装的,其功能与文档中所述的不同,这妨碍了我进一步的调查?
我有:
WinDbg 6.12.0002.633 x86(我的进程是32位)
Windows 7 SP1 x64
I have .NET executable which hosts plugins in separated AppDomains.
Sometimes during application usage one of this plugins locks files and prevents its moving or deletion.
I need to find out who holds File handles?
Issue is intermittent and hard to reproduce. There is 5 plugins.
It is not solution to forbid plugins to access this files or kill handles (like Unlocker does).
I tried:
First, Sysinternals - but it shows only process who holds file with specified name.
Second, as stated in articles and docs about WinDbg I can use !process and !handle, but get next:
0:001> !process
No export process found
0:001> !handle 314 ff 123
Unknown type '123
I can use !handle with less parameters, but my version (for unknown reason) even does not show me file name like in Debug Tutorial Part 5: Handle Leaks. My executable has reference to 100 files.
I'd like to dig in direction with WinDbg, but for some reason it, installed from Windows 7 SDK, differs in functions from stated in docs, which prevents my further investigation?
I have:
WinDbg 6.12.0002.633 x86 (my process is 32 bit)
Windows 7 SP1 x64
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道文件被锁定,那么最简单的方法是在进程上运行 ProcMon 并监视该文件并查看哪个线程打开了它,然后在 Windbg 中检查该线程。您可以通过右键单击操作并转到属性来查看哪个线程在 procmon 中打开了文件。这将为您提供线程 ID 和线程堆栈跟踪。
如果你不能这样做,我会尝试完全卸载 Windbg,然后安装 x64 版本。 x64 可以同时打开 x86 和 x64,然后再次尝试命令。
If you know the file being locked then the easiest thing to do would be to run ProcMon on your process and monitor the file and see which thread opened it up and then check on that thread in windbg. You can see which thread opened up a file in procmon by right clicking on the operation and going to properties. That will give you the thread ID and the thread stack trace.
If you can't do that I would try uninstalling windbg completely and then install the x64 version. The x64 can open both x86 and x64 and then try the commands again.