如何使用C#监视进程的IO活动? [英] How to monitor process' IO activity using C#?

查看:176
本文介绍了如何使用C#监视进程的IO活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用FileSystemWatcher,我们可以监视特定文件系统的IO活动,但是是否总能知道哪个正在运行的进程导致该IO?

Using FileSystemWatcher we can monitor the IO activity of a particular file system, but is there anyway to know that which one of the running processes is causing that IO?

更具体地说,假设一个正在运行的进程即. abc.exe在驱动器D上创建文件text.txt.我们可以使用FileSystemWatcher监视是否在驱动器D中创建了名为text.txt的文件,但是我们可以通过编程方式确定名为abc.exe的进程正在创建该特定文件.在驱动器D中?

More specifically, suppose a running process viz. abc.exe is creating a file text.txt on drive D. We can monitor that a file named text.txt has been created in drive D using FileSystemWatcher, but can we determine programmatically that a process named abc.exe is creating that particular file in drive D?

推荐答案

handle.exe是一种命令行工具,允许以编程方式访问打开了特定文件或目录的程序.

handle.exe from SysInternals is a command line tool that allow programmatic access to which program has a particular file or directory open.

C:\>handle.exe c:\Windows\system32\stdole2.tlb

产生此输出:

Handle v3.42
Copyright (C) 1997-2008 Mark Russinovich
Sysinternals - www.sysinternals.com
devenv.exe         pid: 5240    184: C:\Windows\System32\stdole2.tlb
Ssms.exe           pid: 5000    1F4: C:\Windows\System32\stdole2.tlb

可以通过编程方式进行解析.

Which can be parsed programmatically.

http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

这篇关于如何使用C#监视进程的IO活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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