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();
                }
            }
        }
    }
  • 相关阅读:
    1.时间复杂度与空间复杂度分析
    数据结构与算法之重头再来
    MySQL时间字段与业务代码取出的时间不一致问题
    [redtiger]在线靶场level3
    win10 卡顿 MsMpEng.exe进程
    react 笔记 局部打印 print
    react table td 自动换行
    kali apt-get update release文件过期
    ubuntu怎么切换到root用户,切换到root账号方法
    winscp连接kali 使用预置密码验证 拒绝访问
  • 原文地址:https://www.cnblogs.com/wenming205/p/1889519.html
Copyright © 2011-2022 走看看