Solved

Get Process List with their current CPU utilization percentage

Posted on 2010-09-02
8
918 Views
Last Modified: 2013-12-04
For a Win32 C++ console application, I need to be able to enumerate the list of processes and get a CPU utilization percentage for each process, similar to what appears in the task manager.

I can't use .NET
I can't use Delphi (for some reason so many examples are for delphi)
I can only use Win32 and C++.

How do I achieve that?
0
Comment
Question by:ronenmagid1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33589621
You can take this program from MSDN:
http://msdn.microsoft.com/en-us/library/ms682623(VS.85).asp
This is a Win32 console application.
0
 

Author Comment

by:ronenmagid1
ID: 33589658
thanks pgnatyuk, this is to enumerate processes, anything on getting their current CPU utilization % snapshot?
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33589716
Add GetProcessTimes to the previous example:
http://msdn.microsoft.com/en-us/library/ms683223

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33589741
I think everything's explained in this article:
Determine CPU usage of current process (C++ and C#)
http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/

0
 

Author Comment

by:ronenmagid1
ID: 33589791
One thing that's unclear about GetProcessTimes is the timespan. This seems like a statistical tool that can tell me,

"your application has been up for 5 weeks"
"your application used 1 week of CPU time"

Therefore I can deduce that overall, my process took 20% of the CPU during its lifetime.

however, what if I need a more "real time" monitoring? what if an app that took 1% over two weeks suddenly peaks to 99% CPU? how will I catch that in real time like TASK MANAGER does? This is really what I'm interested in, not over-time statistics but a rather "current" snapshot, based on the last x seconds.

Is there anything like that I can already use? or do I simply have to track the process for those X seconds and, monitor the elapsed time, and "sample" its CPU usage myself using deltas?

I mean, I can do this myself, but was wondering whether there's a ready made value I can pick up somewhere.
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 33589859
Read the article. There is the code you need. Download it. CpuUsage class has GetUsage method. Take a look.



0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33589912
Another approach (performance counters):
http://www.codeproject.com/KB/system/cpuusageByDudiAvramov.aspx
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33590084
Windows SysInternals. Process Explorer v12.04
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question