Get process executed by mono


from https://stackoverflow.com/questions/26374761/get-process-executed-by-mono-on-gnu-linux





public static int process_count(string application_name) {

int rc = 0;
string cmdline = "";
Process[] processlist = Process.GetProcesses();

foreach (Process p in processlist) {

cmdline = "";
//Console.WriteLine("PID : " + theprocess.Id + " " + theprocess.ProcessName);

if (p.ProcessName.Contains("mono")) {
Console.WriteLine("PID : " + p.Id + " " + p.ProcessName + " " + p.MainModule.FileName);
cmdline = File.ReadAllText("/proc/" + p.Id.ToString() + "/cmdline");
Console.WriteLine("CMDLINE : "+cmdline);
}

if (p.ProcessName.Contains("cli")) {
Console.WriteLine("PID : " + p.Id + " " + p.ProcessName + " " + p.MainModule.FileName);
cmdline = File.ReadAllText("/proc/" + p.Id.ToString() + "/cmdline");
Console.WriteLine("CMDLINE : " + cmdline);
}


if (cmdline.Contains(application_name)) {
Console.WriteLine("Found existing process: {0} ID: {1}", p.ProcessName, p.Id);
rc++;
}
}
return (rc);
}






留言

熱門文章