How to get process information in C #?

How to get process usage information (cpu, memory, disk and network ) in a C # application?

PS System.Diagnostics.Process and System.Diagnostics.PerformanceCounter do not provide information about drives and network usage. I do not use it.

+4
source share
4 answers
System.Text.StringBuilder sb = new System.Text.StringBuilder(); var currentProcess = System.Diagnostics.Process.GetCurrentProcess(); sb.AppendLine("Process information"); sb.AppendLine("-------------------"); sb.AppendLine("CPU time"); sb.AppendLine(string.Format("\tTotal {0}", currentProcess.TotalProcessorTime)); sb.AppendLine(string.Format("\tUser {0}", currentProcess.UserProcessorTime)); sb.AppendLine(string.Format("\tPrivileged {0}", currentProcess.PrivilegedProcessorTime)); sb.AppendLine("Memory usage"); sb.AppendLine(string.Format("\tCurrent {0:N0} B", currentProcess.WorkingSet64)); sb.AppendLine(string.Format("\tPeak {0:N0} B", currentProcess.PeakWorkingSet64)); sb.AppendLine(string.Format("Active threads {0:N0}", currentProcess.Threads.Count)); 

and etc.

+2
source

As a starter, get a list of all processes and focus on it:

  using System.Diagnostics; //... Process[] all = Process.GetProcesses(); foreach (Process thisProc in all) { string Name = thisProc.ProcessName; //... } 
+1
source

Add this line to your use list:

 using System.Diagnostics; 

Now you can get the list of processes using the Process.GetProcesses() method, as shown in this example:

 Process[] processlist = Process.GetProcesses(); foreach(Process theprocess in processlist) { Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id); } 
0
source

System.Diagnostics has a class called Process that allows you to statically retrieve Processess by name, ID, etc. So you can do something like

 Process p = Process.GetCurrentProcess(); int pageMemSize = p.PagedMemorySize; 

There are many different class properties. Take a look at the Process class here.

0
source

All Articles