There are several command line commands that come in handy: sample and top .
If you want to write your own program, you can use the sysctl system call to get this information. However, this is rather tedious.
I would recommend installing the procfs file system (built using MacFUSE). This would create a new βdirectoryβ in /proc that contains a lot of useful information for each application (for example, memory usage, processor usage, locks, open files, sockets, threads, etc.). The site provides an example of how to access. Then you can just script to access these files.
notnoop
source share