zoukankan      html  css  js  c++  java
  • 获取cpu使用率,获取某一进程cpu使用率

    using System;
    using System.Diagnostics;

    namespace MyConsole
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    string filePath = "E:\\render\\bin\\render.exe";
                
    string argument = "\\\\192.168.12.166\\ceshi_Project\\scenes\\ceshi.mb";
                
    try
                {
                    Process p 
    = Process.Start(filePath, argument);
                    p.PriorityClass 
    = ProcessPriorityClass.BelowNormal;
                    
    //获取cpu使用率
                    PerformanceCounter cpuUsage = new PerformanceCounter("Processor""% Processor Time""_Total");

                    
    //获取某一进程cpu使用率
                    PerformanceCounter renderUsage = new PerformanceCounter("Process""% Processor Time", p.ProcessName);
                    
    do
                    {
                        Console.WriteLine(
    "---------------------");
                        Console.WriteLine(
    "总使用率:{0:p1}", cpuUsage.NextValue() / 100);
                        Console.WriteLine(
    "{1}使用率:{0:p1}", renderUsage.NextValue() / 100, p.ProcessName);
                        System.Threading.Thread.Sleep(
    1000);
                    }
                    
    while (true);
                }
                
    catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.Read();
                }
            }
        }
    }
  • 相关阅读:
    前台线程与后台线程的区别
    触发器
    Asp.net AutopostBack 属性
    Spring实战拆书--SpringBean
    侣行APP
    用android去写一个小程序
    java如何使用JUnit进行单元测试
    JDK的安装与配置以及eclipse的使用
    软件工程第一次作业(1)
    软件工程第一次作业(2)
  • 原文地址:https://www.cnblogs.com/wenming205/p/1889519.html
Copyright © 2011-2022 走看看