I want to know, how can we find user's process 开发者_开发百科statistics about resource utilization( like CPU, Memory) using c program and without using any user command tool. Currently I am running ubuntu 10.10. Thanks
The canonical way these days is to parse the information in the /proc
virtual filesystem procfs
. It contains textual information on nearly all aspects of the system, including detailed per-process statistics. The information is structured, and is intended for ease of parsing and programmatic access. (This is how tools such as ps
work.)
For example, to query the I/O metrics of a given process, you would read the file under /proc/<pid>/io
. This contains a series of name: value
pairs, like so:
rchar: 14823550
wchar: 138670414
syscr: 11549
syscw: 3013
read_bytes: 483328
write_bytes: 8192
cancelled_write_bytes: 0
For detailed information, see:
- "The /proc Filesystem" - kernel reference documentation
精彩评论