Listing the running applications with memory & processor usage

Hi Experts,

I have a good one ;)

I'd like a procedure that will return the list of running applications  and the amount of memory and processor used by each, at a particular moment. The idea is to monitor the system's behaviour for various reasons so I'll be calling this procedure very often.

I hope I'm being clear enough, thank you,

LVL 14
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hmmmm, this will give you the list of running applications (Processes)

uses TLHelp32
  hSnapshot : THandle;
  ProcessEntry : TProcessEntry32;
  done : BOOL;
    hSnapshot := CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    ProcessEntry.dwSize := sizeof( TProcessEntry32 );
    done := Process32First( hSnapshot, ProcessEntry );
    while ( done = true ) do begin
      ////////////////////////////////////  ListBox1.Items.Add((ProcessEntry.szExeFile));
      done := Process32Next( hSnapshot, ProcessEntry );
    CloseHandle( hSnapshot );

Let me see what I can come up for the CPU useage of each....

I believe there is a function in the API which resembles something like



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Something like

  PH : THandle;
  hProcess : THandle;

  lpUserTime : TFileTime;

  hProcess:= GetProcessId(?);


  if PH <> 0 then
  GetProcessTimes(PH, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);

EsopoAuthor Commented:

Your process listing codes works very well. The GetProcessTimes I don't understand. I tried to place it somewhere in the middle and it started by asking for a declaration for GetProcessId.

I played around with the ProcessEntry information and realized most of the process had parent processes (ProcessEntry.th32ParentProcessID). Although its excellent to have the process list (and its processor usage eventually ;) I would also need the user friendly names of this process or a list of the running applications so the user know what  IEXPLORER.EXE is, something like " - Microsoft Internet Explorer" insted of the exe name.

Basically what I want is to provide the user (and my application) with a list similar to the task administrator in Win2000, with a list of the current applications, a list of the process with CPU usage + memory usage and my own performance algorithms.

I'll be doing my own research about this, but any help here will be very useful.


JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

EsopoAuthor Commented:
I think the answer for the processor usage is in this link (thanks shane for the google groups idea, I wasn't aware google had news groups ;)

Can you help me make sense of this?
Yeah, don't you love google groups!


You dont need all that, cause you have that code already

Basically, to get the CPU useage time, you take the Now time and minus the lpCreationTime

Remember to use the FileTimeToDateTime function i posted in the other post, to convert lpCreationTime to a TDateTime

Also, when you subtract these, you are going to get the number of days between those, which you will have to multiple by 24 to get the number of hours.

There are lots of Function on Google groups to get what you are looking for - i.e. diff between dates
EsopoAuthor Commented:
> Yeah, don't you love google groups!
I think I'm about to!

I guess what we have up until here is about all I need for the CPU part.

Now, two things:
First I guess the easiest one is the list of the running applications. You gave me the process, although I appreciate that, I need the applications as well cause my users won't get what those small names will stand for.

Then there's the memory usage, you think you can help me with that?
Let me see what i can come up with

EsopoAuthor Commented:
Hey Shane, sorry to leave this Q unattended for so long.
I'm still missing the memory usage thing, but will see into it this week, maybe we'll have a solution by friday.

Thank you for your constant help!
EsopoAuthor Commented:
Hey Shane!

I'm back. I know I deserve a name-calling session for leaving this Q out in the open for so long, but I had some issues that parted me from the net for a while.

Anyway, I'm back, got my hands on this project again and plan to see it through very soon. I'll be burning my brain with the code, hopefully we can come up with a function that will serve the delphi community for many years to come... (I feel I owe, you know?)

I'll be back with my findings very soon.

EsopoAuthor Commented:
This has been open too long. I am one step away from getting my code to work but can't find the time to finish it, as soon as I get it right I'll post it here for future reference, thanks for you help.

Also, this is supported by the information here:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.