How to get %CPU usage of a process
Hi there,
I need to get %CPU usage of process , I tried following method on Redhat 7.3 Linux 2.4.18-3
1. read /proc/<PID>/stat (utime) entry and save in val1
2. read same /proc/<PID>/stat (utime) entry after 5 seconds and store in val2
3. calculate by using (val2 - val1) / 500 (since jiffies is 1/100 of second).
Does this make any sense.
But when I look at command output of ps -auxw, %CPU usage is about 50-60%(for eg) for daemons (i.e., <PID> above method).
This is a different value than I calculated using above method.
Please let me know
1. if above method is not correct, let me know correct method to calculate %CPU usage of process.
2. Is there any IOCTL calls to process management in Linux where i can get automated value of %CPU usage.
Thanks in Advance.
-KOTRESH.D
|