Accessing CPU/RAM usage (like with Task Manager, but via API!)?

前端 未结 3 792
野的像风
野的像风 2021-01-21 08:43

Is there a specific way to access \"task manager\" information with the Windows API? I have done a fair bit of searching on the matter, but I can\'t seem to find an API call tha

3条回答
  •  误落风尘
    2021-01-21 09:43

    You can use the following Windows API to retrieve various process counters in C/C++ program.

    It retrieves information about the memory usage of the specified process.

    BOOL WINAPI GetProcessMemoryInfo(
      _In_   HANDLE Process,
      _Out_  PPROCESS_MEMORY_COUNTERS ppsmemCounters,
      _In_   DWORD cb
    );
    

    There is complete example on MSDN, which explains how it can be used to retrieve such information for your process.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms682050%28v=vs.85%29.aspx

    You have mentioned that you would like to fetch the information on continuous basis(with some time interval as task manager do). To achieve this you may want to write the complete logic(mentioned in MSDN) inside a function and call it after some time delay(Sleep(1second)).This way you should be able to fetch all these information of your program till it executes.

提交回复
热议问题