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);
}