Querying Process Information

The Process class is the central abstraction to deal with processes. A series of static methods enables you to obtain Process instances by name, process ID, or unfiltered. We used this capability earlier in this book when discussing LINQ because the process list is a nice nontrivial data source that speaks to the imagination of many readers (at least, I think so). The following code shows this, also emphasizing the availability of many properties on Process objects:

var memoryHogs = from p in Process.GetProcesses()                 where p.WorkingSet64 > 50 * 1024 * 1024 /* 50 MB */                 select p;foreach (var memoryHog in memoryHogs)    Console.WriteLine(memoryHog);

The WorkingSet64 ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.