想知道进程读写磁盘的状况,能够获取当前进程或指定进程的IO计数。spa
#include <Windows.h> int get_io_bytes(ULONGLONG * read_bytes, ULONGLONG * write_bytes,ULONGLONG * wct,ULONGLONG * rct) { IO_COUNTERS io_counter; HANDLE hProcess=GetCurrentProcess();//获取当前进程句柄 if(GetProcessIoCounters(hProcess, &io_counter)) { if(read_bytes) *read_bytes = io_counter.ReadTransferCount;//字节数 if(write_bytes) *write_bytes = io_counter.WriteTransferCount; if(wct) *wct=io_counter.WriteOperationCount;//次数 if(rct) *rct=io_counter.ReadOperationCount; return 0; } return -1; }
若是是检查其余进程的话,首先设法拿到进程ID,而后进程句柄须要以下获取。
须要为这个句柄指定查询权限,注意第一个参数:
hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid);
获取完毕后,将句柄关闭:
CloseHandle(hProcess); code