简体   繁体   中英

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.

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

     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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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