Measuring process memory usage in Cocoa / Objectice-C?

I want to create a program that can display the amount of RAM used by Google Chrome. Chrome uses a process for each tab and each plug-in / extension (mostly), so you cannot confidently view the activity monitor for the amount of RAM.

My idea was to give the program a name for the process (Chrome), and it would search for each child process. Then I will add the amount of memory received by the entire parent process to get the answer.

The problem is that I cannot find a class that can give me the amount of memory received by the process.

I found a way to get the PID on behalf of the application (and vice versa) with the sample code PIDFromBSDProcessName written in C. But I can not find the memory, either in NSRunningApplication or in NSTask from the NSWorkSpace classes.

Any idea?

If you have any advice, I will also read about it with pleasure!

+6
source share
1 answer

One of the problems is that between the various processes that the application will be very difficult to detect, shared memory is likely to be used. Also, if it also displays a file similar to history records / archives, which will look as if it had normal memory, which makes such a tool very inaccurate.

0
source

Source: https://habr.com/ru/post/893166/


All Articles