Re: CPU usage of particular process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Does your machine have multiple CPUs?

Regards,
Neha

On Mon, May 20, 2013 at 4:05 AM, Rahul Bedarkar <rpal143@xxxxxxxxx> wrote:
Hi,

I am trying to write small program to get CPU usage for a particular process. My logic is to read user, nice, system, idle values from /proc/stat. Then read user and system time from /proc/<pid>/stat. Then wait for some time and again read same values. After that I am doing following calculations 
CPU% = (no_of_processor * (process_cpu_usage2-process_cpu_usage1) * 100 ) / (total_cpu_usage2-total_cpu_usage1)

When I compare my output with top, it looks like correct, but sometimes it is more than 100. Is my logic correct here ? Please correct me if I am worng.

Regards,
Rahul 

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux