Mac OS X Process Example from C / C ++

The Sample Process feature in Activity Monitor is a very useful thing. However, I need to do the same (take samples) of a specific process from another running process (C / C ++) or the command line.

Is there any way to do this? I have been looking for this for several days without any luck.

+7
terminal process macos
source share
2 answers

There is a sample command line utility.

Example:

 sample Safari -file /dev/stdout 

It will get exactly the same result with Activity Monitor.

+12
source share

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.

+2
source share

All Articles