LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1466|回复: 1

/proc/<pid>/stat中求某个进程占用CPU百分比问题

[复制链接]
发表于 2006-12-5 16:21:43 | 显示全部楼层 |阅读模式
http://community.csdn.net/Expert/Top...asp?id=4801613
上面网站有这样一个程序:

char buf[64];
sprintf(buf,"/proc/%d/stat",pid);
FILE* fid = fopen(buf,"r");
if(fid){
fscanf(fid,"%d %s %c %d %d %d %d %d %lu %lu "
"%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld "
"%ld %ld %lu %lu %ld %lu %lu %lu %lu %lu",
&pstat[0],buf,&pstat[2],&pstat[3],&pstat[4],&pstat[5],&pstat[6],&pstat[7],
&pstat[8],&pstat[9],&pstat[10],&pstat[11],&pstat[12],&pstat[13],&pstat[14],&pstat[15],
&pstat[16],&pstat[17],&pstat[18],&pstat[19],&pstat[20],&pstat[21],&pstat[22],&pstat[23],
&pstat[24],&pstat[25],&pstat[26],&pstat[27],&pstat[28],&pstat[29],&pstat[30]);
fclose(fid);

。。。。。

ut = pstat[13];
st = pstat[14];
cut = pstat[15];
cst = pstat[16];

。。。。。
ts = time(NULL) - lasttime;
百分比=(ut+st-sut-sst)/ts

谁知道“ts=time(NULL) - lasttime”中的lasttime和time(NULL)指的是什么时间,小弟我急用呀。
 楼主| 发表于 2006-12-19 19:56:26 | 显示全部楼层
问题自己已解决
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表