C#: Checking if a process is running

For some server running process, we might actually have to monitor if a process.

If it is not running, we might actually need to restart the process.

We can check if a particular program is runing by using GetProcessesByName.  Here we check if notepad is running.

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace GetProcess
    /// <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 a process on the local computer, using the process id.  
            // Change the ID according to the process ID running in your Desktop
             Process localById = Process.GetProcessById(6132);


        static void Main()

            MyProcess myProcess = new MyProcess();



Series Navigation<< C#: Display all processes running
C#: Try catch block >>