使用此代码,这适用于 Windows。对于 Linux(Ubuntu)“Linux 中未提供 PerformanceCounter”
PerformanceCounter counter = GetPerfCounterForProcessId(process.Id); //Just gets process by id dont worry...
var processUsages = counter.NextValue();
double processUsage = counter.NextValue() / Environment.ProcessorCount;
Run Code Online (Sandbox Code Playgroud)
在 Linux 中,如何通过 ID 调用此方法来获取进程的 CPU 使用率?
asp.net-core ×1