none
how to get cpu and memory usage values of apps just like Task Manager on Windows 10? RRS feed

  • Question

  • Hi,

    I want to make an application which observes all applications and processes on Task Manager and checks cpu and memory usage of applications. If an application uses memory or cpu more than a threshold, my application should kill this app.

    Task Manager on Windows 10 shows the processes as grouped by its application name. For example, Skype application has two processes which are "SkypeBridge" and "RuntimeBroker", they are shown as grouped by "Skype" name and Task Manager shows total cpu and memory usage of these processes. What I am trying to do is the same. I want to get cpu and memory values of these groups just same as Task manager.

    I tried performance counter class, wmi queries but none of them gave the same values on Task Manager.

    Thanks for help!

    Thursday, October 10, 2019 6:17 AM

All replies

  • Task Manager uses PDH (PdhCollectQueryData and so on)
    Thursday, October 10, 2019 8:13 AM
  • Hello,

    Look on PerformanceCounter from

    https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics?redirectedfrom=MSDN&view=netframework-4.8



    Sincerely, Highly skilled coding monkey.

    [Moderator edit: This post was originally flagged as abusive. It is true that the OP had mentioned that he had already tried using performance counters and didn't find them satisfactory, but marking the post as "abusive" is excessive. This makes it appear as "red" in the forum and can lead to the whole thread being deleted. It may not be very useful, but it is not "abusive"]
    Thursday, October 10, 2019 8:22 AM
  • What criteria would you use?  There's nothing wrong with an application using 100% of the CPU for a period of time.  If you do a search-and-replace in a long Word document, that's a CPU bound task that will use 100%.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, October 10, 2019 6:27 PM
  • "If an application uses memory or cpu more than a threshold, my application should kill this app."
    why don't you instead limit the process to only use X amount of CPU and memory?
    Job Limits and Notifications
    an example can be fond here: jobrun
    Thursday, October 10, 2019 7:26 PM
  • No problem - no more reference to documentation...

    By the way - if there are no satisfaction with classes targeted to do the job - there will be no satisfaction as there no way to get result quicker and easier.


    Sincerely, Highly skilled coding monkey.

    Friday, October 11, 2019 10:45 AM
  • Hi @EckiS,

    Thanks for replying! Because my program works as a watchdog which will control all other server programs on a server machine. It is responsible for restarting unhandled closed programs and checking ram, memory usage of all programs. Therefore the program should not limit the usage of itself, but it should limit other programs' usages..



    • Edited by Baacus35 Saturday, October 12, 2019 7:45 PM
    Saturday, October 12, 2019 7:44 PM
  • you can manage other programs, when you attach them to a job.
    Saturday, October 12, 2019 8:28 PM