Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating Per Process Memory Usage on MacOS

I am currently working on a small side project which I would like to add some statistics to regarding CPU usage / Memory Usage / Opened FDs / etc. but on a per process level.

I have the CPU usage working correctly, however the issue I am running into is with the memory. I cannot find any APIs for retrieving or calculating the memory usage similar to how 'Activity Monitor' does it in the process info section.

What APIs are available to be able to calculate the 'Real/Virtual/Shared/Private' memory usages? I have used the host_statistics() however this only gives me the basic VM info from what I can tell. I have also looked into task_info() but this too does not appear to have the memory break down I am looking for.

like image 426
slagathor Avatar asked Nov 28 '25 11:11

slagathor


1 Answers

Apple makes the source code for the top utility available. That should help you work out how to access all the process information it displays, at least. This does include a bunch of different memory statistics.

like image 100
pmdj Avatar answered Nov 30 '25 05:11

pmdj



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!