通过系统调用获取特定进程占有的内存量,CPU占有率
时间:2007-03-06
来源:互联网
我想通过系统调用获取特定进程占有的内存量,还有CPU占有率.
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
int getrusage(int who, struct rusage *rusage);
函数返回后,在rusage所指结构中有一个成员long ru_ixrss; /* integral shared memory size */(这是man page 中的注释)
我把整个结构也给出来:
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* max resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data */
long ru_isrss; /* integral unshared stack */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary " */
};
打印出来后,发现ru_ixrss是个很大的整数.应该不大可能是正常的内存量.这些成员的具体指的什么意思?有没有熟悉的朋友,可以讨论一下吧!
或者有什么好方法得到内存和cpu占有率,系统调用的形式.
另外这个函数在APUE中没有提到,是不是不提倡用?
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
int getrusage(int who, struct rusage *rusage);
函数返回后,在rusage所指结构中有一个成员long ru_ixrss; /* integral shared memory size */(这是man page 中的注释)
我把整个结构也给出来:
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* max resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data */
long ru_isrss; /* integral unshared stack */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary " */
};
打印出来后,发现ru_ixrss是个很大的整数.应该不大可能是正常的内存量.这些成员的具体指的什么意思?有没有熟悉的朋友,可以讨论一下吧!
或者有什么好方法得到内存和cpu占有率,系统调用的形式.
另外这个函数在APUE中没有提到,是不是不提倡用?
作者: levinee 发布时间: 2007-03-06
man getrusage
...
ru_ixrss an ``integral ' ' value indicating the amount of memory used
by the text segment that was also shared among other pro-
cesses. This value is expressed in units of kilobytes *
ticks-of-execution. Ticks are statistics clock ticks. The
statistics clock has a frequency of sysconf(_SC_CLK_TCK)
ticks per second.
....
这个值是共享的正文段内存大小和系统嘀嗒数的乘积,大一些也正常了。
...
ru_ixrss an ``integral ' ' value indicating the amount of memory used
by the text segment that was also shared among other pro-
cesses. This value is expressed in units of kilobytes *
ticks-of-execution. Ticks are statistics clock ticks. The
statistics clock has a frequency of sysconf(_SC_CLK_TCK)
ticks per second.
....
这个值是共享的正文段内存大小和系统嘀嗒数的乘积,大一些也正常了。
作者: iisbsd 发布时间: 2007-03-12
那这个线程占用了多少内存,是那个字段呢? 或者说,这个结构体里面没有?通过其他方式获取的,ps?
作者: bluefish625 发布时间: 2011-12-06
http://blog.csdn.net/crazyguang/article/details/2407263
http://topic.csdn.net/u/20091224/14/5f84b381-1e43-474d-a69c-3e28cb83aae1.html
http://topic.csdn.net/u/20091224/14/5f84b381-1e43-474d-a69c-3e28cb83aae1.html
作者: axengine 发布时间: 2011-12-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28