System.Diagnostics.ProcessManager.IsProcessRunning C# (CSharp) Method

IsProcessRunning() public static method

Gets whether the process with the specified ID is currently running.
public static IsProcessRunning ( int processId ) : bool
processId int The process ID.
return bool
        public static bool IsProcessRunning(int processId)
        {
            // kill with signal==0 means to not actually send a signal.
            // If we get back 0, the process is still alive.
            int output = Interop.Sys.Kill(processId, Interop.Sys.Signals.None);
            // If kill set errno=EPERM, assume querying process is alive.
            return 0 == output || (-1 == output && Interop.Error.EPERM == Interop.Sys.GetLastError());
        }

Same methods

ProcessManager::IsProcessRunning ( int processId, int processIds ) : bool
ProcessManager::IsProcessRunning ( int processId, string machineName ) : bool

Usage Example

Example #1
0
        /// <devdoc>
        ///    <para>
        ///       Returns a new <see cref='System.Diagnostics.Process'/> component given a process identifier and
        ///       the name of a computer in the network.
        ///    </para>
        /// </devdoc>
        public static Process GetProcessById(int processId, string machineName)
        {
            if (!ProcessManager.IsProcessRunning(processId, machineName))
            {
                throw new ArgumentException(SR.Format(SR.MissingProccess, processId.ToString()));
            }

            return(new Process(machineName, ProcessManager.IsRemoteMachine(machineName), processId, null));
        }