Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve memory usage for another process in C#

I've seen methods here for retrieving CPU and memory usage for the CURRENT process, i.e. 'my application', but I need to write a service that monitors the performance of a separate application.

In C++ I used PSAPI for this, but I'm new to C# and would like to use the managed framework if possible. Has anyone done this?

like image 813
buzzard51 Avatar asked Aug 31 '26 19:08

buzzard51


1 Answers

        long memory;
        Process[] notepads;
        notepads = Process.GetProcessesByName("Notepad.exe");
        memory = notepads[0].PrivateMemorySize64;
        Console.WriteLine("Memory used: {0}.", memory);
more info here:
https://msdn.microsoft.com/en-us/library/s80a75e5(v=vs.90).aspx
like image 145
Janusz Nowak Avatar answered Sep 03 '26 09:09

Janusz Nowak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!