简体   繁体   English

有没有办法检查特定 Windows 服务正在使用多少内存?

[英]there is a way to check how much ram is being used by a specific windows service?

I need to know how much ram is used at that time by a windows service or program, but I don't know how to get there.我需要知道当时 Windows 服务或程序使用了多少内存,但我不知道如何到达那里。

this makes me restart a service that I indicated on the service controller but I have to do it only if the ram exceeds a certain value that I have to indicate这让我重新启动我在服务控制器上指示的服务,但只有当 ram 超过我必须指示的某个值时,我才必须这样做

     ServiceController service = new ServiceController("MSSQLSERVER");
        try
        {
            int millisec1 = Environment.TickCount;
            TimeSpan timeout = TimeSpan.FromMilliseconds(100000);

            service.Stop();
            service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);

            int millisec2 = Environment.TickCount;
            timeout = TimeSpan.FromMilliseconds(50000 - (millisec2 - millisec1));

            service.Start();
            service.WaitForStatus(ServiceControllerStatus.Running, timeout);

        }
        catch
        {
            Console.WriteLine("Errore");
            Console.ReadLine();
        }

If you only know the process name, you can do如果您只知道进程名称,则可以执行

var process = Process.GetProcessesByName("explorer").FirstOrDefault();
var memoryUsed = process?.PrivateMemorySize64;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM