/proc/pid/stat 을 이용해서 프로세스별 cpu 점유율 구하는 방법에 대한 질문입니다.
글쓴이: waydi / 작성시간: 월, 2011/06/06 - 3:18오후
안녕하세요.
/proc/[pid]/stat 을 이용해서 프로세스 별 cpu 점유율을 구하는 작업을 하고 있는데요.
ps 나 top에서 나오는것처럼 점유율을 구하고 싶은데 생각처럼 잘 안돼서 이렇게 질문 드립니다.
static int want_this_proc_pcpu(proc_t *buf){
unsigned long long used_jiffies;
unsigned long pcpu = 0;
unsigned long long avail_jiffies;
if(!want_this_proc(buf)) return 0;
used_jiffies = buf->utime + buf->stime;
if(include_dead_children) used_jiffies += (buf->cutime + buf->cstime);
avail_jiffies = seconds_since_boot * Hertz - buf->start_time;
if(avail_jiffies) pcpu = (used_jiffies << 24) / avail_jiffies;
buf->pcpu = pcpu; // fits in an int, summing children on 128 CPUs
return 1;
}
ps 소스를 보니 이런식으로 되어 있는데요, 실제로 해보니까 정확하게 잘 구해지지 않더라구요.
뭔가 더 해야하는 계산이 있는건가요?
답변부탁드립니다~
Forums:
댓글 달기