Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a process's ram usage

Tags:

c#

I have been having some trouble figuring out how exactly I get a process's ram usage. (How much ram it is currently consuming, not how much is reserved, or its max or min)

Lets say I have a process running in the back ground, Java.exe, it is allowed to use 1024mb of ram, how can I tell how much ram it is currently using.

I am starting the process myself, so I have access to the Process object, I would just like a little more clarification on what property is the one for me.

like image 768
Meiscooldude Avatar asked May 09 '09 03:05

Meiscooldude


People also ask

Why is my RAM getting used so much?

All computer memory is connected to the CPU and RAM. However, the high memory usage problem is mainly due to the overcrowding of many internal processes. Therefore, it helps to stop the unnecessary programs and applications that are running. Open the Task Manager and check any extra programs you aren't using.

How can I measure my RAM usage?

Press Ctrl + Shift + Esc to launch Task Manager. Or, right-click the Taskbar and select Task Manager. Select the Performance tab and click Memory in the left panel. The Memory window lets you see your current RAM usage, check RAM speed, and view other memory hardware specifications.

How can I monitor my RAM usage over time?

Check Computer Memory Usage EasilyTo open up Resource Monitor, press Windows Key + R and type resmon into the search box. Resource Monitor will tell you exactly how much RAM is being used, what is using it, and allow you to sort the list of apps using it by several different categories.


2 Answers

I found this on msdn and it is working

System.Diagnostics.Process proc = ...; // assign your process here :-)  int memsize = 0; // memsize in KB PerformanceCounter PC = new PerformanceCounter(); PC.CategoryName = "Process"; PC.CounterName = "Working Set - Private"; PC.InstanceName = proc.ProcessName; memsize = Convert.ToInt32(PC.NextValue()) / (int)(1024); PC.Close(); PC.Dispose(); 
like image 113
Laz Nikolaj Andersen Avatar answered Oct 14 '22 13:10

Laz Nikolaj Andersen


If you are purely interested in physical memory, you probably want WorkingSet64, which gives "the amount of physical memory allocated for the associated process." Understand that this value constantly fluctuates, and the value this call gives you may not be up to date. You may also be interested in PeakWorkingSet64, which gives "the maximum amount of physical memory used by the associated process."

like image 35
Matthew Flaschen Avatar answered Oct 14 '22 14:10

Matthew Flaschen