How can I get the PID of the parent process of my application

WMI is the easier way to do this in C#. The Win32_Process class has the ParentProcessId property. Here’s an example: using System; using System.Management; // <=== Add Reference required!! using System.Diagnostics; class Program { public static void Main() { var myId = Process.GetCurrentProcess().Id; var query = string.Format(“SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}”, myId); … Read more

Determine programmatically if a program is running

You can walk the pid entries in /proc and check for your process in either the cmdline file or perform a readlink on the exe link (The following uses the first method). #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <dirent.h> #include <sys/types.h> pid_t proc_find(const char* name) { DIR* dir; struct dirent* ent; char* … Read more