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
|