1. Roland Smith
  2. PowerBuilder
  3. Thursday, 22 February 2024 13:47 PM UTC

I'm looking to automatically kill a process if it gets over a certain CPU percentage. I need to know what API function to call to get the CPU percent.

I already know how to get a list of processes.

Brad Mettee Accepted Answer Pending Moderation
  1. Thursday, 22 February 2024 17:47 PM UTC
  2. PowerBuilder
  3. # 1
Comment
  1. Roland Smith
  2. Thursday, 22 February 2024 17:56 PM UTC
Thanks. It looks like you have to get the kernel/user times of all processes and do some math.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 22 February 2024 16:24 PM UTC
  2. PowerBuilder
  3. # 2

Hi Roland;

  FWIW: Have a look at my STD Framework's "Windows Explorer" App. It can locate any process and kill it ...

http://chrispollach.blogspot.com/2024/02/explorer.html

The Explorer works in either M-Code or P-Code compiles and either 32 or 64 bit mode.

The framework is Free & open Source, so feel free to use my code as applicable.   HTH  ;-)

Regards ... Chris

Comment
  1. Brad Mettee
  2. Thursday, 22 February 2024 17:46 PM UTC
Chris,

I think you missed the point that Roland is trying to find the CPU usage for a given process BEFORE his app decides if it needs to kill it.

  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 22 February 2024 17:55 PM UTC
Yes, just add something like this then into the processing Roland wants to do ...

https://www.manageengine.com/products/exchange-reports/powershell/how-to-check-cpu-and-memory-utilization-using-powershell.html

;-)
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 22 February 2024 14:36 PM UTC
  2. PowerBuilder
  3. # 3

Unsure if this will help, but it appears that WMI (Windows Management Instrumentation) may provide a means of doing this:

    https://learn.microsoft.com/en-us/windows/win32/wmisdk/monitoring-performance-data

If you have not already done so, I suggest checking other web sites, such as StackOverflow.com

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.