Write the read data to the Log.txt file and create a new Log.txt file in the project first
Public classProgram { Public Const stringLogger_file ="Log.txt"; Public Static voidLogger (stringFormatString,params Object[] args) { stringinput =string. Format (formatString, args); System.IO.File.AppendAllText (Logger_file,string. Concat (Input,"\ r \ n")); } Static voidMain (string[] args) { stringWindowTitle =string. Empty; Longmemorysize; Longpagedmemorysize; Longpeakworking; stringProcessName; intpid; Process[] PS=process.getprocesses (); foreach(Process PinchPS) { if(P.mainwindowhandle! =NULL) {ProcessName=P.processname; Getworkingset (ProcessName); //pid = p.id; //memorysize = p.nonpagedsystemmemorysize64; ////machinename = p.machinename; //pagedmemorysize = p.pagedmemorysize64; //peakworking = P.peakworkingset64; //windowtitle = P.mainwindowtitle; //Logger ("Time {0}:memorysize{1};pagedmemorysize{2};peakworking{3};{4};pid:{5}", DateTime.Now, Memorysize.tostring (), pagedmemorysize.tostring (), peakworking.tostring (), windowtitle,pid);}} Console.WriteLine ("completed please check log.txt, enter any key to exit. "); Console.readkey (); } Public Static voidGetworkingset (stringprocessName) { //var processName = "Taskmgr"; using(varProcess = Process.getprocessesbyname (processName) [0]) using(varP1 =NewPerformanceCounter ("Process","working set-private", ProcessName)) using(varP2 =NewPerformanceCounter ("Process","working Set", ProcessName)) {Console.WriteLine (process. ID); //Note divided by the number of CPUsConsole.WriteLine ("{0}{1:n} KB","Working Set (Process Class)", process. WorkingSet64/1024x768); Console.WriteLine ("{0}{1:n} KB","Working Set", process. WorkingSet64/1024x768); Console.WriteLine ("{0}{1:n} KB","Private Working Set", p1. NextValue ()/1024x768); Logger ("{0}; memory (dedicated working set) {1:n};pid:{2}; program name: {3}", DateTime.Now, p1. NextValue ()/1024x768, process. Id.tostring (), processName); //Thread.Sleep (+); } } }
Msdn:http://msdn.microsoft.com/zh-cn/library/system.diagnostics.process.pagedmemorysize64.aspx
- Memory-Working set: the sum of the amount of memory in a private working set and the amount of memory that the process is using and can be shared by other processes.
- Memory-Peak Working set: The maximum number of working set memory used by the process.
- Memory-Working Set increment: The amount of change in the working set memory used by the process.
- Memory-Private Working set: a subset of the working set that specifically describes the amount of memory that a process is using and cannot share with other processes.
- Memory-Commit Size: The amount of virtual memory that is reserved for use by a process.
- Memory-Paged Pool: The number of paged kernel memory allocated by the kernel or driver on behalf of the process. Paged memory is memory that can be written to other storage media, such as a hard disk.
- Memory-nonpaged Pool: The number of non-paged kernel memory allocated by the kernel or driver on behalf of the process. Non-paged memory is memory that cannot be written to other storage media.
Source: What does the Task Manager memory column mean? http:// windows.microsoft.com/z h-cn/windows7/what-do-the-task-manager-memory-columns-mean