C # Process Monitoring

Source: Internet
Author: User

The information retrieved in the following example involves all instances of the current process, notepad running on the local computer, and notepad running on a specific computer that uses the computer alias and IP address. all processes running on instances, local computers, and remote computers, and specific processes that use process IDs on local or remote computers.

using System;using System.Diagnostics;using System.ComponentModel;namespace MyProcessSample{    /// <summary>    /// Shell for the sample.    /// </summary>    class MyProcess    {                               void BindToRunningProcesses()        {            // Get the current process.            Process currentProcess = Process.GetCurrentProcess();                        // Get all instances of Notepad running on the local            // computer.            Process [] localByName = Process.GetProcessesByName("notepad");                        // Get all instances of Notepad running on the specifiec            // computer.            // 1. Using the computer alias (do not precede with "\\").            Process [] remoteByName = Process.GetProcessesByName("notepad", "myComputer");                        // 2. Using an IP address to specify the machineName parameter.             Process [] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");                                    // Get all processes running on the local computer.            Process [] localAll = Process.GetProcesses();                        // Get all processes running on the remote computer.            Process [] remoteAll = Process.GetProcesses("myComputer");                        // Get a process on the local computer, using the process id.            Process localById = Process.GetProcessById(1234);                        // Get a process on a remote computer, using the process id.            Process remoteById = Process.GetProcessById(2345, "myComputer");                    }                static void Main()        {                                   MyProcess myProcess = new MyProcess();                        myProcess.BindToRunningProcesses();            }        }}

There are several attributes that you can be interested in the Process class:
Description
BasePriority gets the basic priority of the associated process.
The Container obtains the IContainer, which contains the Component. (Inherited from Component .)
EnableRaisingEvents gets or sets whether the Exited event should be triggered when the process is terminated.
ExitCode gets the value specified when the associated process is terminated.
ExitTime gets the time when the associated process exits.
Handle returns the local Handle of the associated process.
HandleCount gets the number of handles opened by the process.
HasExited gets the value indicating whether the associated process has been terminated.
Id to obtain the unique identifier of the associated process.
MachineName gets the name of the computer on which the associated process is running.
MainModule obtains the main module of the associated process.
Main1_whandle gets the window handle of the Main Window of the associated process.
Mainwindowtitle: Obtain the title of the Main Window of the process.
Maxworkingset obtains or sets the maximum allowable working set size of associated processes.
Minworkingset obtains or sets the minimum allowable working set size of the associated process.
Modules gets the modules loaded by the associated process.
Nonpagedsystemmemorysize gets the size of the non-paging system memory allocated to this process.
Nonpagedsystemmemorysize64 gets the amount of non-paging system memory allocated for the associated process.
Pagedmemorysize: obtains the size of the paging memory.
Pagedmemorysize64 obtains the amount of paging memory allocated for the associated process.
Pagedsystemmemorysize obtains the system memory size of the paging.
Pagedsystemmemorysize64 obtains the amount of paging system memory allocated for the associated process.
Peakpagedmemorysize obtains the peak paging memory size.
Peakpagedmemorysize64 obtains the maximum amount of memory in the virtual memory paging file used by the associated process.
Peakvirtualmemorysize obtains the peak virtual memory size.
Peakvirtualmemorysize64 obtains the maximum virtual memory used by the associated process.
Peakworkingset obtains the peak working set size of the associated process.
PeakWorkingSet64 obtains the maximum amount of physical memory used by the associated process.
PriorityBoostEnabled gets or sets a value that indicates whether the operating system temporarily increases the priority of associated processes when the main window has focus.
PriorityClass gets or sets the overall priority category of the associated process.
PrivateMemorySize obtains the size of the dedicated memory.
PrivateMemorySize64 gets the amount of dedicated memory allocated for the associated process.
PrivilegedProcessorTime gets the privileged processor time of this process.
ProcessName: get the name of the process.
ProcessorAffinity gets or sets the processor on which threads in this process can run.
Responding gets the value indicating whether the user interface of the process is Responding.
SessionId: obtains the Terminal Service session identifier of the associated process.
Site to obtain or set the ISite of Component. (Inherited from Component .)
StandardError gets the stream used to read the error output of the application.
StandardInput gets the stream used to write the input to the application.
StandardOutput gets the stream used to read application output.
StartInfo gets or sets the attribute of the Start method to be passed to Process.
StartTime gets the start time of the associated process.
SynchronizingObject gets or sets the object used to block the event processing program called by the process exit event.
Threads gets a group of Threads running in the associated process.
TotalProcessorTime gets the total processor time of the process.
UserProcessorTime gets the user processor time of this process.
VirtualMemorySize obtains the virtual memory size of the process.
VirtualMemorySize64 gets the virtual memory allocated for the associated process.
WorkingSet obtains the physical memory usage of associated processes.
WorkingSet64 gets the amount of physical memory allocated for the associated process.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.