Solved

Listing the running applications with memory & processor usage

Posted on 2004-04-01
11
209 Views
Last Modified: 2010-04-05

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,

Esopo.
0
Comment
Question by:Esopo
  • 7
  • 4
11 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 320 total points
Comment Utility
Hmmmm, this will give you the list of running applications (Processes)

uses TLHelp32
var
  hSnapshot : THandle;
  ProcessEntry : TProcessEntry32;
  done : BOOL;
begin
  try
    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 );
    end;
  finally
    CloseHandle( hSnapshot );
  end;
end;


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

GetProcessTime(.....................................);

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Something like

  PH : THandle;
  hProcess : THandle;

  lpCreationTime,
  lpExitTime,
  lpKernelTime,
  lpUserTime : TFileTime;


  hProcess:= GetProcessId(?);

  PH := OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, hProcess);

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

 Shane
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
Shane,

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 "Hotmal.com - 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.

Thanks,

Esopo.
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
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 ;)

http://groups.google.com/groups?hl=es&lr=&ie=UTF-8&oe=UTF-8&threadm=3ec24268%241%40newsgroups.borland.com&rnum=8&prev=/groups%3Fq%3DDelphi%2B%2B%2BlpCreationTime%26hl%3Des%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D3ec24268%25241%2540newsgroups.borland.com%26rnum%3D8

Can you help me make sense of this?
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Yeah, don't you love google groups!

<SMILE>

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
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
> 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?
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Let me see what i can come up with

Shane
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
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!
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
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.

Esopo.
0
 
LVL 14

Author Comment

by:Esopo
Comment Utility
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:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20945822.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now