1

When I sum the WorkingSet64 property of a collection of processes generated from Process.GetProcesses(), the sum is less than the total physical memory usage indicated by GlobalMemoryStatusEx.

When I run an operation on a process (for example, to load a large file or inject code, etc), the physical memory of the system jumps up, but the WorkingSet64 sum does not track this.

Is there a way to acquire the actual, non-shared physical memory usage of a particular process?

  • This isn't a C# question and there's no simple answer. Both Windows and Linux use many different types of memory pages and pools that are displayed in a very simplified way in task managers or through functions. How about pages that *should* be paged-out but haven't been removed yet? They can be put back in use if requested but don't count against a process's total. – Panagiotis Kanavos Dec 22 '17 at 08:47
  • If you really care about the *exact* answer, you should check Windows Internals to find about the different types of pools and select the counters you want. A quick&dirty alternative is to read all memory counters for a process and keep those that look interesting. Or you can keep the `Working Set - Private` counter, which aggregates various other counters. – Panagiotis Kanavos Dec 22 '17 at 08:49
  • Check [Windows Process Memory Usage Demystified](http://blogs.microsoft.co.il/sasha/2016/01/05/windows-process-memory-usage-demystified/) too, which explains the different memory pools with the help of VMMap – Panagiotis Kanavos Dec 22 '17 at 08:51

1 Answers1

0

You can get the process’s private working set.

stackoverflow answer:

“The private working set is the amount of memory used by a process that cannot be shared among other processes, while working set includes the memory shared by other processes.”

You can use a ProcessCounter to access this value.

Process thisProc = Process.GetCurrentProcess();
PerformanceCounter PC = new PerformanceCounter();

PC.CategoryName = "Process";
PC.CounterName = "Working Set - Private";
PC.InstanceName = thisProc.ProcessName;
int privateMemory = PC.Next()/1000; //this will be in KB.
Mátray Márk
  • 455
  • 5
  • 17