I need to get the 'Commit size' (Windows Task Manager > Details) of a process in C#.
At first sight the Process
class does not provide a relevant property. Can somebody help me?
Edited
private static void ShowCommitSize(string processName)
{
Process process = Process.GetProcessesByName(processName).FirstOrDefault();
if (process != null)
{
var pagedMemMb = ConvertBytesToMegabytes(process.PagedMemorySize64);
Console.WriteLine(process.ProcessName + "\t" + process.Id + "\t" + Math.Round(pagedMemMb, 3) + " MB");
}
Console.ReadLine();
}
static double ConvertBytesToMegabytes(long bytes)
{
return (bytes / 1024f) / 1024f;
}
Output
There is a difference between my calculated Commit Size and the 'Commit Size' in Task Manager. Any ideas?
Solution
private static void ShowCommitSize(string processName)
{
var process = Process.GetProcessesByName(processName).FirstOrDefault();
if (process != null)
{
var memKb = ConvertBytesToKilobytes(process.PagedMemorySize64);
Console.WriteLine(process.ProcessName + "\t" + process.Id + "\t" + memKb.ToString("N") + " K");
}
Console.ReadLine();
}
static double ConvertBytesToKilobytes(long bytes)
{
return (bytes / 1024f);
}
This value is in the PagedMemorySize64 property. The documentation mentions that this the "Page File Size" process performance counter and over here it is documented that this is referred to as "Commit Size" in Task Manager on Vista/2008 (and I would assume newer OSes).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.