getrusage
来源:互联网 发布:alphago 算法 编辑:程序博客网 时间:2024/06/06 09:40
#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);
getrusage函数有两个参数。第一个参数可以设置为RUSAGE_SELF或者RUSAGE_CHILDREN。如果设置成 RUSAGE_SELF,那么将会以当前进程的相关信息来填充rusage(数据)结构。反之,如果设置成RUSAGE_CHILDREN,那么 rusage结构中的数据都将是当前进程的子进程的信息。( RUSAGE_CHILDREN
Return resource usage statistics for all children of the calling process that have terminated and been waited for. These statistics will
include the resources used by grandchildren, and further removed descendants, if all of the intervening descendants waited on their termi‐
nated children.)
linux 增加了第三个参数 RUSAGE_THREAD (since Linux 2.6.26)
Return resource usage statistics for the calling thread.
rusage(数据)结构定义在/usr/include/sys/resource.h中。它含有以下成员变量:
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 " */
};
示例:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
int
main(int argc, char **argv)
{
struct rusage buf;
if(argc == 2) {
system(argv[1]);
}else {
fprintf(stderr,"./getrusage /"ls -l >/dev/null/"/n");
exit(0);
}
int err = getrusage(RUSAGE_CHILDREN, &buf);
//int err = getrusage(RUSAGE_SELF, &buf);
printf("ERR=%d/n", err);
printf("%20s:%ld/%ld/t%s/n", "ru_utime",
buf.ru_utime.tv_sec, buf.ru_utime.tv_usec,
"user time used (secs/usecs)");
printf("%20s:%ld/%ld/t%s/n", "ru_stime",
buf.ru_stime.tv_sec,
buf.ru_stime.tv_usec,
"system time used (secs/usecs)");
printf("%20s:%-10ld/t%s/n",
"ru_maxrss",
buf.ru_maxrss,
"maximum resident set size");
printf("%20s:%-10ld/t%s/n",
"ru_ixrss",
buf.ru_ixrss,
"integral shared memory size");
printf("%20s:%-10ld/t%s/n",
"ru_idrss",
buf.ru_idrss,
"integral unshared data size");
printf("%20s:%-10ld/t%s/n",
"ru_isrss",
buf.ru_isrss,
"integral unshared data stack size");
printf("%20s:%-10ld/t%s/n",
"ru_minflt",
buf.ru_minflt,
"page reclaims");
printf("%20s:%-10ld/t%s/n",
"ru_majflt",
buf.ru_majflt,
"page faults");
printf("%20s:%-10ld/t%s/n",
"ru_nswap",
buf.ru_nswap,
"swaps");
printf("%20s:%-10ld/t%s/n",
"ru_inblock",
buf.ru_inblock,
"block input operations");
printf("%20s:%-10ld/t%s/n",
"ru_oublock",
buf.ru_oublock,
"block output operations");
printf("%20s:%-10ld/t%s/n",
"ru_msgsnd",
buf.ru_msgsnd,
"messages sent");
printf("%20s:%-10ld/t%s/n",
"ru_msgrcv",
buf.ru_msgrcv,
"messages received");
printf("%20s:%-10ld/t%s/n",
"ru_nsignals",
buf.ru_nsignals,
"signals received");
printf("%20s:%-10ld/t%s/n",
"ru_nvcsw",
buf.ru_nvcsw,
"voluntary context switches");
printf("%20s:%-10ld/t%s/n",
"ru_nivcsw",
buf.ru_nivcsw,
"involuntary context switches");
exit(0);
}
- getrusage
- getrusage性能
- getrusage 函数调用
- Linux:getrusage的用法
- Linux:getrusage的用法
- Linux中getrusage的使用
- Linux中,getrlimit(),setrlimit(),getrusage()
- Unix/Linux下 getrusage 的用法
- Unix/Linux下 getrusage 的用法
- Linux系统调用--getrusage函数详解
- 使用getrusage获取进程使用系统资源信息
- Linux系统调用--getrusage函数详解
- 进程信息之getrusage系统调用
- Linux系统调用--getrusage函数详解
- 监控进程使用内存 getrusage 函数简介及使用
- 九个PHP有用功能funcGetArgs,Glob,memoryGetUsage,getrusage,__FILE__,uniqid,serialize,gzcompress,注册停止
- 本机资源状态的获取和设置 (getrlimit,setrlimit,getrusage,getpagesize)
- Measure time in Linux - getrusage vs clock_gettime vs clock vs gettimeofday
- .net 服务器端缓存与客户端缓存
- 简单的引导程序
- ACM常用算法及其相应的练习题
- C#命名规则
- Alignment of the Planets
- getrusage
- C语言数据类型概要图
- C#实现快捷键(系统热键)响应
- 80x86通用寄存器
- 城堡
- 右键菜单
- C#中利用存储过程(含有参数)返回dataset
- 在 Linux 上找出并解决程序错误的主要方法
- C++ vector 排序