C# 获取运行进程的Mono运行时

C# 获取运行进程的Mono运行时,c#,linux,process,mono,C#,Linux,Process,Mono,我在使用Mono运行时、Ubuntu服务器和C#代码运行进程时遇到问题 我正在尝试使用以下方法获取流程列表: Process.GetProcesses().ToList<Process>().ForEach((s) => { Console.WriteLine(s.ProcessName); }); 所以我得到了一个有效的输出: 根25597 0.0 0.4 23540 9132?Sl Sep26 0:07单声道 /var/lib/sa

我在使用Mono运行时、Ubuntu服务器和C#代码运行进程时遇到问题

我正在尝试使用以下方法获取流程列表:

Process.GetProcesses().ToList<Process>().ForEach((s) => {
            Console.WriteLine(s.ProcessName);
        });
所以我得到了一个有效的输出:

根25597 0.0 0.4 23540 9132?Sl Sep26 0:07单声道 /var/lib/sarg/Watcher.exe根目录29226 0.0 0.0 5184 1112 pts/0 S+15:04 0:00/bin/bash-cps-aux | grep Watcher root 29228 0.0 0.0 4392 820分/0秒+15:04 0:00 grep观察者

如您所见,这一行:

/var/lib/sarg/Watcher.exe根目录

我确认我的进程正在运行,但这不是很优雅,我必须解析 输出


如果没有其他选项,我会解析它,但可能有一个选项,我对此一无所知。

尝试使用
Process.getProcessByName(“Watcher”)
,这似乎对我有用。

问题是这个过程被命名为“mono”而不是“watcher”


使用“watcher”永远无法按名称找到进程。测试一些代码并使用以下命令后,您必须获取ProcessByName(“mono”)。

Proccess[] Proc =Process.GetProcessesByName("mono");
我终于在stacktrace上找到了一个例外:

Unhandled Exception: System.NotImplementedException: The requested feature is not implemented.
  at System.Diagnostics.Process.get_SessionId () [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_SessionId ()
  at ProcWatch.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: The requested feature is not implemented.
  at System.Diagnostics.Process.get_SessionId () [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_SessionId ()
  at ProcWatch.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

看看问题:在GNU/Linux上获得MONO执行的进程

该解决方案查找所有进程名称MONO或CLI,然后读取该进程的命令行。 命令行提供MONO执行的应用程序的名称


干杯,我试过了。不工作:/。输出为0个进程。如果我使用“mono”作为名称,效果会很好
Unhandled Exception: System.NotImplementedException: The requested feature is not implemented.
  at System.Diagnostics.Process.get_SessionId () [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_SessionId ()
  at ProcWatch.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: The requested feature is not implemented.
  at System.Diagnostics.Process.get_SessionId () [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_SessionId ()
  at ProcWatch.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
Process.Start("/bin/bash"," -c 'ps -aux | grep Watcher'");