I want to programmatically verify the status of an application to see if it has crashed or stopped. I know how to see if the process exists in C# but can I also see if it is "Not responding"?
You can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time. This will display the process for the current shell with four columns: PID returns the unique process ID.
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
Open the terminal window on Unix. For remote Unix server use the ssh command for log in purpose. Type the ps aux command to see all running process in Unix. Alternatively, you can issue the top command to view running process in Unix.
The “-ef” option of the “ps” command is used to print all the processes running on the system in the standard format.
Everything you need is in System.Diagnostics, for example: to check if a process is responding.
using System;
using System.Diagnostics;
namespace ProcessStatus
{
class Program
{
static void Main(string[] args)
{
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
Console.WriteLine("Process Name: {0}, Responding: {1}", process.ProcessName, process.Responding);
}
Console.Write("press enter");
Console.ReadLine();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With