you can use sysctl
to retrieve the available processes. the SO question "Can we retrieve the applications currently running in iPhone and iPad?" has an answer that should works for macOS … i tried it, simply putting the code in the answer in an Xcode 4.4 new macOS project, #importing and performing an NSLog on the result array rather than returning it, and it neatly displays the collected array of process names and IDs.
and while there is a wealth of information in struct kinfo_proc
and its nested struct extern_proc
, unfortunately for you, i don't see an easy way to retrieve the memory information for individual processes.
for that, you can consult libtop.c
, which is Apple's open source offering. the linked version is from the MacOS X 10.8 library.
in any case, if you combine pulling the available processes from sysctl with the process information retrieval code in libtop.c, you should end up with a programmatic solution for exactly what you're looking for.
and … on the other hand … if you don't mind doing a very small bit of parsing compared to the work this will require, try the SO answer You can use NSTask , only substitute ps aux -m
where that question performs "grep". you'll want to get only the first real line of output from the stream, and you'll have to parse whitespace to get to the column containing the RSS information, but that might be easier than getting what you want via libtop.c , depending upon what you need it for.