如何在Windows中查找特定进程在该时刻的CPU使用情况

How to find the cpu usage of a particular process at that moment of time in Windows

本文关键字:时刻 CPU 用情 情况 Windows 查找 进程      更新时间:2023-10-16

是否可以在Windows中以编程方式(以任何语言)了解正在运行/空闲进程的CPU使用率?

如果你不关心支持旧的Windows版本(早于Windows XP SP1),你可以使用GetSystemTimes Win32 API函数。

否则,必须使用性能计数器。

C#中,您可以执行以下操作:

private PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);
cpuCounter.NextValue(); // it will give you cpu usage

详情请参考此处。