Process monitoring

0

I'm developing a process monitoring application, so to get the programs running I'm using this class:

    
asked by anonymous 08.04.2016 / 14:43

1 answer

0

Win32_Process has the CreationDate property, which despite the name is a DateTime. To know the idle time of a program, simply find out the total time and subtract the user's time ( UserModeTime ) and the spent time core ( KernelModeTime )

An example, using the default C # classes

    public static void Main( string[] args )
    {
        var procs = Process.GetProcesses().Where( x => x.ProcessName.Contains( "chrome" ) ).ToList();
        foreach ( var proc in procs )
        {
            var timeTotal = DateTime.Now - proc.StartTime;
            var timeProc = proc.TotalProcessorTime;
            var timeIdle = timeTotal.Subtract( timeProc );

            Console.WriteLine( proc.Id + " total " + timeTotal + " user+kernel " + timeProc + " idle " + timeIdle );
        }
    }

Produce things like:

2570 total 1.18:52:22.8433460 user+kernel 00:48:02 idle 1.18:04:20.843346000:11:57.9100000
    
08.04.2016 / 22:43