Немножко исходников
private static class Linux
{
public static void GetMemorySize (out long virtualSize, out long residentSize)
{
const string VmSize = "VmSize:";
const string VmRSS = "VmRSS:";
virtualSize = 0;
residentSize = 0;
using (System.IO.StreamReader rd = System.IO.File.OpenText("/proc/self/status"))
{
while (!rd.EndOfStream && ((virtualSize == 0) || (residentSize == 0)))
{
string line = rd.ReadLine();
if (line.StartsWith(VmSize))
{
string s = line.Substring(VmSize.Length, line.Length - VmSize.Length - 3);
long x;
long.TryParse(s, out x);
virtualSize = x * 1024;
}
else if (line.StartsWith(VmRSS))
{
string s = line.Substring(VmRSS.Length, line.Length - VmRSS.Length - 3);
long x;
long.TryParse(s, out x);
residentSize = x * 1024;
}
}
}
}
}
private static class Win64
{
private struct PROCESS_MEMORY_COUNTERS_EX
{
public uint cb;
public uint PageFaultCount;
public ulong PeakWorkingSetSize;
public ulong WorkingSetSize;
public ulong QuotaPeakPagedPoolUsage;
public ulong QuotaPagedPoolUsage;
public ulong QuotaPeakNonPagedPoolUsage;
public ulong QuotaNonPagedPoolUsage;
public ulong PagefileUsage;
public ulong PeakPagefileUsage;
public ulong PrivateUsage;
}
[System.Runtime.InteropServices.DllImport("Psapi.dll")]
private static extern long GetProcessMemoryInfo (long process, ref PROCESS_MEMORY_COUNTERS_EX x, uint cb);
[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
private static extern long GetCurrentProcess ();
public static void GetMemorySize (out long virtualSize, out long residentSize)
{
PROCESS_MEMORY_COUNTERS_EX x = new PROCESS_MEMORY_COUNTERS_EX();
x.cb = 80;
GetProcessMemoryInfo(GetCurrentProcess(), ref x, 80);
virtualSize = (long)x.PrivateUsage;
residentSize = (long)x.WorkingSetSize;
}
}