开发者

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

The Sample Process feature in Activity Monitor i开发者_C百科s 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.


There is a command-line utility sample.

Example:

sample Safari -file /dev/stdout

It will get exactly the same output with Activity Monitor.


There are some few commandsline application that come in handy: sample and top.

If you want to write your own program, you can use the sysctl system call to get such information. However, it's quite tedious.

I would recommend installing procfs file system (built with MacFUSE). This would create a new "directory" at /proc that contains a lot of useful information for each application (e.g. memory usage, cpu usage, locks, opened files, sockets, threads, etc). The site gives a sample of how it can be accessed. Then you can simply script your access to those files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜