Does your machine have multiple CPUs?<br><br>Regards,<br>Neha<br><br><div class="gmail_quote">On Mon, May 20, 2013 at 4:05 AM, Rahul Bedarkar <span dir="ltr">&lt;<a href="mailto:rpal143@gmail.com" target="_blank">rpal143@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>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/&lt;pid&gt;/stat. Then wait for some time and again read same values. After that I am doing following calculations </div>


<div>CPU% = (no_of_processor * (process_cpu_usage2-process_cpu_usage1) * 100 ) / (total_cpu_usage2-total_cpu_usage1)</div><div><br></div><div>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.</div>


<div><br></div><div>Regards,</div><div>Rahul </div></div>
<br>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><br>