<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Determine CPU usage of current process (C++ and C#)</title>
	<atom:link href="http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/</link>
	<description>Code and musings by Ben Watson</description>
	<lastBuildDate>Wed, 28 Jul 2010 12:43:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: vaishali</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-143678</link>
		<dc:creator>vaishali</dc:creator>
		<pubDate>Thu, 08 Jul 2010 10:20:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-143678</guid>
		<description>Deekshit,

As you have mentioned that your code is working for single process or program ,
please let me know what i need to add to the exiting code.
please!! :cry: 
i want a code that takes a program name as argument and gives it cpu utilization as output.

thank u.</description>
		<content:encoded><![CDATA[<p>Deekshit,</p>
<p>As you have mentioned that your code is working for single process or program ,<br />
please let me know what i need to add to the exiting code.<br />
please!! <img src='http://www.philosophicalgeek.com/wp-includes/images/smilies/icon_cry.gif' alt=':cry:' class='wp-smiley' /><br />
i want a code that takes a program name as argument and gives it cpu utilization as output.</p>
<p>thank u.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: P.C.</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-136057</link>
		<dc:creator>P.C.</dc:creator>
		<pubDate>Sat, 27 Mar 2010 20:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-136057</guid>
		<description>I would disagree to sentence &quot;Kernel, User, and Idle sum to total time, which is approximately wall-time.&quot;

Idle time returned from GetSystemTimes is most probably a part of the Kernel time. 

GetProcessTimes returns Kernel time without any Idle time periods because they belong to a different process.

So, the calculation takes the Idle time into account but I would say, it is correct.</description>
		<content:encoded><![CDATA[<p>I would disagree to sentence &#8220;Kernel, User, and Idle sum to total time, which is approximately wall-time.&#8221;</p>
<p>Idle time returned from GetSystemTimes is most probably a part of the Kernel time. </p>
<p>GetProcessTimes returns Kernel time without any Idle time periods because they belong to a different process.</p>
<p>So, the calculation takes the Idle time into account but I would say, it is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-134571</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Mon, 08 Mar 2010 21:35:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-134571</guid>
		<description>Remy, GetTickCount() is supported by Windows 2000 (http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx), but GettickCount64 is not supported until Vista/2008.

For GetSystemTimes(), I think your only solution is to use the officially-unsupported function NtQuerySystemInformation  (http://msdn.microsoft.com/en-us/library/ms724509(VS.85).aspx, look for SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION). I would put usage of this inside some #ifdef so it&#039;s only used in Windows 2000/XP, because this method could change or be removed in future versions of Windows.</description>
		<content:encoded><![CDATA[<p>Remy, GetTickCount() is supported by Windows 2000 (<a href="http://msdn.microsoft.com/en-us/library/ms724408(VS.85" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724408(VS.85</a>).aspx), but GettickCount64 is not supported until Vista/2008.</p>
<p>For GetSystemTimes(), I think your only solution is to use the officially-unsupported function NtQuerySystemInformation  (<a href="http://msdn.microsoft.com/en-us/library/ms724509(VS.85" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724509(VS.85</a>).aspx, look for SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION). I would put usage of this inside some #ifdef so it&#8217;s only used in Windows 2000/XP, because this method could change or be removed in future versions of Windows.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Remy</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-134455</link>
		<dc:creator>Remy</dc:creator>
		<pubDate>Sun, 07 Mar 2010 23:50:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-134455</guid>
		<description>Hi Ben, 

I wanted to use your program for my project, but the code uses GetSystemTimes() and GetTickCounts() which don&#039;t seem to be supported by XP/2000.  Is there a quick fix for that?

Thanks ,
Remy</description>
		<content:encoded><![CDATA[<p>Hi Ben, </p>
<p>I wanted to use your program for my project, but the code uses GetSystemTimes() and GetTickCounts() which don&#8217;t seem to be supported by XP/2000.  Is there a quick fix for that?</p>
<p>Thanks ,<br />
Remy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kao</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-109665</link>
		<dc:creator>kao</dc:creator>
		<pubDate>Mon, 03 Aug 2009 01:33:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-109665</guid>
		<description>Oh, I see. Thanks for the answer.  

p/s: Nice to meet you. :)</description>
		<content:encoded><![CDATA[<p>Oh, I see. Thanks for the answer.  </p>
<p>p/s: Nice to meet you. <img src='http://www.philosophicalgeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-109609</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Sun, 02 Aug 2009 16:10:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-109609</guid>
		<description>That code is just test code to use the processor as much as possible, in multiple threads, in order to test the processor usage code.

I would not expect it to match task manager exactly--they are measuring the program at different times, so there will be a little difference. Over time, they should average out to the same, though.</description>
		<content:encoded><![CDATA[<p>That code is just test code to use the processor as much as possible, in multiple threads, in order to test the processor usage code.</p>
<p>I would not expect it to match task manager exactly&#8211;they are measuring the program at different times, so there will be a little difference. Over time, they should average out to the same, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kao</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-109582</link>
		<dc:creator>kao</dc:creator>
		<pubDate>Sun, 02 Aug 2009 10:02:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-109582</guid>
		<description>Hi Ben, I don&#039;t understand every detail why you use thread method &quot;EatItThreadProc&quot;, and every thread method was used 2 times (in your code):

        static void Main(string[] args)
        {
            Console.WriteLine(&quot;Input:&quot;);
            string processName = Console.ReadLine();
            usage.setProcessName(processName);
            
            ThreadPool.QueueUserWorkItem(EatItThreadProc);
            ThreadPool.QueueUserWorkItem(EatItThreadProc);

            ThreadPool.QueueUserWorkItem(WatchItThreadProc);
            ThreadPool.QueueUserWorkItem(WatchItThreadProc);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }

Can you explain for me?

Moreoverer, I try to compare your program and Task manager of Window, they have a little difference. So, your program ran exactly?

Thanks for your reply!</description>
		<content:encoded><![CDATA[<p>Hi Ben, I don&#8217;t understand every detail why you use thread method &#8220;EatItThreadProc&#8221;, and every thread method was used 2 times (in your code):</p>
<p>        static void Main(string[] args)<br />
        {<br />
            Console.WriteLine(&#8220;Input:&#8221;);<br />
            string processName = Console.ReadLine();<br />
            usage.setProcessName(processName);</p>
<p>            ThreadPool.QueueUserWorkItem(EatItThreadProc);<br />
            ThreadPool.QueueUserWorkItem(EatItThreadProc);</p>
<p>            ThreadPool.QueueUserWorkItem(WatchItThreadProc);<br />
            ThreadPool.QueueUserWorkItem(WatchItThreadProc);</p>
<p>            while (true)<br />
            {<br />
                Thread.Sleep(1000);<br />
            }<br />
        }</p>
<p>Can you explain for me?</p>
<p>Moreoverer, I try to compare your program and Task manager of Window, they have a little difference. So, your program ran exactly?</p>
<p>Thanks for your reply!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101444</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:58:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101444</guid>
		<description>&#039;GetProcessesByName&#039;: identifier not found</description>
		<content:encoded><![CDATA[<p>&#8216;GetProcessesByName&#8217;: identifier not found</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101439</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:15:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101439</guid>
		<description>Hi Ben, Sorry about the previous two messages but i am trying to use this program to monitor a particular process so I replaced GetCurrentProcess() by GetProcessesByName(&quot;notepad&quot;) but I am getting an error</description>
		<content:encoded><![CDATA[<p>Hi Ben, Sorry about the previous two messages but i am trying to use this program to monitor a particular process so I replaced GetCurrentProcess() by GetProcessesByName(&#8220;notepad&#8221;) but I am getting an error</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101438</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101438</guid>
		<description>sorry got it working</description>
		<content:encoded><![CDATA[<p>sorry got it working</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101437</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101437</guid>
		<description>hi Ben, i tried building the solution it said it is successfull but i dont get any executable.</description>
		<content:encoded><![CDATA[<p>hi Ben, i tried building the solution it said it is successfull but i dont get any executable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101291</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sat, 30 May 2009 22:36:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101291</guid>
		<description>Hi Ben thats a great program, But how do I make it to monitor a particular process. I still didnot run the code but just want to make sure if we can monitor any process or not.

Thanks,
Bharath</description>
		<content:encoded><![CDATA[<p>Hi Ben thats a great program, But how do I make it to monitor a particular process. I still didnot run the code but just want to make sure if we can monitor any process or not.</p>
<p>Thanks,<br />
Bharath</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-95729</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 21 Apr 2009 14:32:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-95729</guid>
		<description>Peter, look at the documentation for this function on MSDN, specifically the requirements section: http://msdn.microsoft.com/en-us/library/ms724411.aspx</description>
		<content:encoded><![CDATA[<p>Peter, look at the documentation for this function on MSDN, specifically the requirements section: <a href="http://msdn.microsoft.com/en-us/library/ms724411.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724411.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-95634</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Mon, 20 Apr 2009 21:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-95634</guid>
		<description>I have tried to run this program but always get entry point not fount GetTickCount64. I am using xp sp2 and tried to debug the source code from VS2008. do you know the reason?</description>
		<content:encoded><![CDATA[<p>I have tried to run this program but always get entry point not fount GetTickCount64. I am using xp sp2 and tried to debug the source code from VS2008. do you know the reason?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohan</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-92797</link>
		<dc:creator>Rohan</dc:creator>
		<pubDate>Mon, 30 Mar 2009 17:43:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-92797</guid>
		<description>Good Article Ben</description>
		<content:encoded><![CDATA[<p>Good Article Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deekshit</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-91256</link>
		<dc:creator>Deekshit</dc:creator>
		<pubDate>Tue, 17 Mar 2009 18:39:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-91256</guid>
		<description>Hi Ben,

Any idea how to make this just one exe program so that I can copy the exe file to any machine and run the program? 
I havent been able to get past the objects problem, but I modified my program to accept command line arguments, so I&#039;ll just put this into a batch file and run it.

Any ideas?

--Deekshit</description>
		<content:encoded><![CDATA[<p>Hi Ben,</p>
<p>Any idea how to make this just one exe program so that I can copy the exe file to any machine and run the program?<br />
I havent been able to get past the objects problem, but I modified my program to accept command line arguments, so I&#8217;ll just put this into a batch file and run it.</p>
<p>Any ideas?</p>
<p>&#8211;Deekshit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deekshit</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-89929</link>
		<dc:creator>Deekshit</dc:creator>
		<pubDate>Mon, 09 Mar 2009 13:45:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-89929</guid>
		<description>Ben,

that approach doesnt work...
usage[i] will never be initialized to any value. Trying to work on this further

--Deekshit</description>
		<content:encoded><![CDATA[<p>Ben,</p>
<p>that approach doesnt work&#8230;<br />
usage[i] will never be initialized to any value. Trying to work on this further</p>
<p>&#8211;Deekshit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-89484</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 06 Mar 2009 16:15:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-89484</guid>
		<description>I think you have the right idea with the array.

CpuUsage[] usage = new CpuUsage[nProcs];
for (int i=0;i&lt;nProcs;i++) { int per = usage.GetUsage(procName[i]); }</description>
		<content:encoded><![CDATA[<p>I think you have the right idea with the array.</p>
<p>CpuUsage[] usage = new CpuUsage[nProcs];<br />
for (int i=0;i<nProcs;i++) { int per = usage.GetUsage(procName[i]); }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deekshit</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-89422</link>
		<dc:creator>Deekshit</dc:creator>
		<pubDate>Fri, 06 Mar 2009 08:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-89422</guid>
		<description>I can get it to work if I create the CpuUsage objects in this way:

Assuming I want to monitor 2 processes

CpuUsage usage1 = new CpuUsage();
CpuUsage usage2 = new CpuUsage();

and then I can run usage1.getUsage(procName[i]);
and usage2.getUsage(procName[i+1]);


and this approach works, but is not dynamic at all..any tips on how I can get around this problem?

Regards,
Deekshit</description>
		<content:encoded><![CDATA[<p>I can get it to work if I create the CpuUsage objects in this way:</p>
<p>Assuming I want to monitor 2 processes</p>
<p>CpuUsage usage1 = new CpuUsage();<br />
CpuUsage usage2 = new CpuUsage();</p>
<p>and then I can run usage1.getUsage(procName[i]);<br />
and usage2.getUsage(procName[i+1]);</p>
<p>and this approach works, but is not dynamic at all..any tips on how I can get around this problem?</p>
<p>Regards,<br />
Deekshit</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deekshit</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-89421</link>
		<dc:creator>Deekshit</dc:creator>
		<pubDate>Fri, 06 Mar 2009 08:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-89421</guid>
		<description>CpuUsage[] usage = new CpuUsage[nProcs];

Is this what you are referring to Ben? I seem to be a bit lost here. Can you please help Ben?

Regards,
Deekshit</description>
		<content:encoded><![CDATA[<p>CpuUsage[] usage = new CpuUsage[nProcs];</p>
<p>Is this what you are referring to Ben? I seem to be a bit lost here. Can you please help Ben?</p>
<p>Regards,<br />
Deekshit</p>
]]></content:encoded>
	</item>
</channel>
</rss>
