using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
staticclassNat
{
    [StructLayout(LayoutKind.Sequential]
    struct IO_COUNTERS
    {
        public ulong ReadOperationCount;
        public ulong WriteOperationCount;
        public ulong OtherOperationCount;
        public ulong ReadTransferCount;
        public ulong WriteTransferCount;
        public ulong OtherTransferCount;
    }
    [DllImport("kernel32.dll")]
    unsafe static extern bool GetProcessIoCounters(IntPtrProcessHandle,out IO_COUNTERS IoCounters);

[StructLayout(LayoutKind.Sequential,Size=40)]
    privatestruct PROCESS_MEMORY_COUNTERS
    {
        public uint cb;
        public uint PageFaultCount;
        public uint PeakWorkingSetSize;
        public uint WorkingSetSize;
        public uint QuotaPeakPagedPoolUsage;
        public uint QuotaPagedPoolUsage;
        public uint QuotaPeakNonPagedPoolUsage;
        public uint QuotaNonPagedPoolUsage;
        public uint PagefileUsage;
        public uint PeakPagefileUsage;
    }

[DllImport("psapi.dll",SetLastError=true)]
    unsafe static extern bool GetProcessMemoryInfo(IntPtr* hProcess,out PROCESS_MEMORY_COUNTERS*Memcounters,int size);

publicstaticclass IO
    {
        unsafepublicstaticDictionary<string,ulong>GetALLIO(Process procToRtrivIO)
        {
            IO_COUNTERS counters;
            Dictionary<string,ulong> retCountIoDict =newDictionary<string,ulong>();
            IntPtr ptr =System.Diagnostics.Process.GetCurrentProcess().Handle;

GetProcessIoCounters(ptr,out counters);
            retCountIoDict.Add("ReadOperationCount", counters.ReadOperationCount);
            retCountIoDict.Add("WriteOperationCount", counters.WriteOperationCount);
            retCountIoDict.Add("OtherOperationCount", counters.OtherOperationCount);
            retCountIoDict.Add("ReadTransferCount", counters.ReadTransferCount);
            retCountIoDict.Add("WriteTransferCount", counters.WriteTransferCount);
            retCountIoDict.Add("OtherTransferCount", counters.OtherTransferCount);
            return retCountIoDict;
            //return  "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
            //    " Mb of data.";

}
    }
    publicstaticclassMem
    {
        unsafe public staticDictionary<string,uint>GetAllMem(Process procToRtrivMem)
        {

PROCESS_MEMORY_COUNTERS*MemCounters;
            Dictionary<string,uint> retCountMemDict =newDictionary<string,uint>();
            IntPtr ptr =System.Diagnostics.Process.GetCurrentProcess().Handle;

GetProcessMemoryInfo(&ptr,outMemCounters,Marshal.SizeOf(typeof(PROCESS_MEMORY_COUNTERS)));//MemCounters.cb);
            retCountMemDict.Add("cb",MemCounters->cb);
            retCountMemDict.Add("PageFaultCount",MemCounters->PageFaultCount);
            retCountMemDict.Add("PeakWorkingSetSize",MemCounters->PeakWorkingSetSize);
            retCountMemDict.Add("WorkingSetSize",MemCounters->WorkingSetSize);
            retCountMemDict.Add("QuotaPeakPagedPoolUsage",MemCounters->QuotaPeakPagedPoolUsage);
            retCountMemDict.Add("QuotaPagedPoolUsage",MemCounters->QuotaPagedPoolUsage);

retCountMemDict.Add("QuotaPeakNonPagedPoolUsage",MemCounters->QuotaPeakNonPagedPoolUsage);
            retCountMemDict.Add("QuotaNonPagedPoolUsage",MemCounters->QuotaNonPagedPoolUsage);
            retCountMemDict.Add("PagefileUsage",MemCounters->PagefileUsage);
            retCountMemDict.Add("PeakPagefileUsage",MemCounters->PeakPagefileUsage);

return retCountMemDict;
            //return  "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
            //    " Mb of data.";

}
    }
}

参考:using unsafe code in C# asp.net   http://stackoverflow.com/questions/17207310/using-unsafe-code-in-c-sharp-asp-net

collectiong memory usage information for a processhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms682050(v=vs.85).aspx

在C#中调用psapi.dll内置的GetProcessMemoryInfo函数http://social.microsoft.com/Forums/it-IT/650197e0-a21a-4f5e-a974-23f074f52a55/cpsapidllgetprocessmemoryinfo?forum=visualcshartzhchs

ASP.NET(C#)获取当前计算机CPU内存使用率等相关信息http://luzinwbing.blog.163.com/blog/static/113805840201031093415658/

不安全代码只会在使用/unsafe编译情况下使用  http://lixiaorong223.blog.163.com/blog/static/44011629200993181241924/

wmi获得进程的虚拟内存与任务管理器中显示的不一致  http://bbs.csdn.net/topics/260033107

C#实现进程内存信息获取的更多相关文章

  1. swift的类型系统及类型(内存)信息获取:接口、编译运行时、反射、内存布局

    swift是静态语言,没有在运行时保存类型的结构信息(isa.class). 一.self.Self.Type.typeof extension Collection where Self.Eleme ...

  2. Android中获取系统内存信息以及进程信息-----ActivityManager的使用(一)

    本节内容主要是讲解ActivityManager的使用,通过ActivityManager我们可以获得系统里正在运行的activities,包括 进程(Process)等.应用程序/包.服务(Serv ...

  3. Linux系统下输出某进程内存占用信息的c程序实现

    在实际工作中有时需要程序打印出某个进程的内存占用情况以作参考, 下面介绍一种通过Linux下的伪文件系统/proc 计算某进程内存占用的程序实现方法. 首先, 为什么会有所谓的 伪文件 呢. Linu ...

  4. 获取系统中所有进程&线程信息

    读书笔记--[计算机病毒解密与对抗] 目录: 遍历进程&线程程序 终止进程 获取进程信息 获取进程内模块信息 获取进程命令行参数 代码运行环境:Win7 x64 VS2012 Update3 ...

  5. 显示所有APP的进程详细信息(进程ID、进程所在UID、进程占用内存、进程名)

    main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...

  6. 使用python获取CPU和内存信息的思路与实现(linux系统)

    linux里一切皆为文件,在linux/unix的根文件夹下,有个/proc文件夹,这个/proc 是一种内核和内核模块用来向进程(process)发送信息的机制(所以叫做"/proc&qu ...

  7. 【.net 深呼吸】启动一个进程并实时获取状态信息

    地球人和火星人都知道,Process类既可以获取正在运行的进程,也可以启动一个新的进程.在79.77%应用场合,我们只需要让目标进程顺利启动就完事了,至于它执行了啥,有没有出错,啥时候退出就不管了. ...

  8. Android获取cpu和内存信息、网址的代码

      android获取手机cpu并判断是单核还是多核 /** * Gets the number of cores available in this device, across all proce ...

  9. PHP检测获取内存信息

    PHP也可以检测获取到Windows的内存信息,而且代码还挺简单,无意发现的,觉得以后能用上,在此与大家分享. 本代码将得到总内存.初始使用等内存信息: <?php echo "初始: ...

随机推荐

  1. 机器学习算法笔记1_2:分类和逻辑回归(Classification and Logistic regression)

    形式: 採用sigmoid函数: g(z)=11+e−z 其导数为g′(z)=(1−g(z))g(z) 如果: 即: 若有m个样本,则似然函数形式是: 对数形式: 採用梯度上升法求其最大值 求导: 更 ...

  2. win32 ag + xargs

    需要使用-0 d:\Apps\AutoHotkey\scripts>ag 2b89eaa_r13_ad1 -l -0|xargs -0 sed -i s/2b89eaa_r13_ad1/2b89 ...

  3. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. windows安装rabbitMQ服务

    简介: RabbitMQ是流行的开源消息队列系统,用erlang语言开发.RabbitMQ是AMQP(高级消息队列协议)的标准实现. windows安装rabbitMQ服务步骤: 首先需要安装 Erl ...

  5. 【41.43%】【codeforces 560C】Gerald's Hexagon

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 跟我学AngularJs:Service、Factory、Provider依赖注入使用与差别

    林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka        本教程使用AngularJs版本号:1.5.3        AngularJ ...

  7. php实现数组中的逆序对(归并排序实现:排序 辅助数组)

    php实现数组中的逆序对(归并排序实现:排序 辅助数组) 一.总结 这题用归并排序  线段树   树状数组 等操作的复杂度应该都是小于n方的 二.php实现数组中的逆序对 题目描述 在数组中的两个数字 ...

  8. <Linux> Xen虚拟机镜像的安装

    了解系统安装在哪个磁盘上:fdisk -l 建立存放虚拟机镜像的目录:mkdir /mnt/vmx 更改文件系统格式: mkfs -t ext4 /dev/sda或者/dev/sdb(系统不在的那个硬 ...

  9. MySQL 监控-innotop

    innotop 编写者Balon Schwartz,<高性能MySQL>的作者之一. innotop的作用为实时地展示服务器正在发生的事情,监控innodb,监控多个MySQL实例,是一款 ...

  10. zxing的使用及优化

    二维码介绍 zxing项目是谷歌推出的用来识别多种格式条形码的开源项目,项目地址为https://github.com/zxing/zxing,zxing有多个人在维护,覆盖主流编程语言,也是目前还在 ...