Search code examples
macosprocessterminalactivity-monitor

Sample a process on Mac OS X from a C/C++ program


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

Is there any way to do this? I have been googling for this since a few days without any luck.


Solution

  • There is a command-line utility sample.

    Example:

    sample Safari -file /dev/stdout
    

    It will get exactly the same output with Activity Monitor.