0

I need to get the 'Commit size' (Windows Task Manager > Details) of a process in C#.

enter image description here

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?

enter image description here

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

1 Answer 1

2

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).

4
  • thank you! I've edited my question, and used the PagedMemorySize64 property. There is still a difference between calculated Commit Size and the value seen in Task Manager. Any ideas?
    – BertAR
    Commented Oct 19, 2017 at 7:24
  • @BertAR which part of the difference are you asking about? 124552 Kb = 121.6 Mb. Are you asking about the 0.6 Mb or mistakenly comparing kB to Mb? Did the value change between screenshots? Commented Oct 19, 2017 at 7:38
  • thank you for the swift replies! Indeed my conversion was wrong. Have a nice day.
    – BertAR
    Commented Oct 19, 2017 at 7:57
  • @BertAR I'm looking into this now. What was the issue with your conversion? I think I know what the problem was but I wanted to make sure before I added it to the answer. Commented Dec 4, 2018 at 2:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.