Reputation: 11063
I am having a problem getting running processes with Mono runtime, Ubuntu server and C# Code.
Im trying to get the process list using:
Process.GetProcesses().ToList<Process>().ForEach((s) => {
Console.WriteLine(s.ProcessName);
});
And I get the following list: (resumed)
rsyslogd perl perl mono smbd sshd bash sudo
So, I guess I have a similar problem as executing a Java Jar. I can see the mono console running but I can't get his child processes running so I can't develop another application to act as a monitor. I need to check if the application is running all time.
I managed to achieve it doing a /bin/bash command:
Process.Start("/bin/bash"," -c 'ps -aux | grep Watcher'");
So I get a valid output:
root 25597 0.0 0.4 23540 9132 ? Sl Sep26 0:07 mono /var/lib/sarg/Watcher.exe root 29226 0.0 0.0 5184 1112 pts/0 S+ 15:04 0:00 /bin/bash -c ps -aux | grep Watcher root 29228 0.0 0.0 4392 820 pts/0 S+ 15:04 0:00 grep Watcher
as you can see, this line:
/var/lib/sarg/Watcher.exe root
reafirms that my process ir running but this is not very elegant and I have to parse the output.
I will parse it If there is not other option but maybe there is one and I don't know about it.
Upvotes: 0
Views: 5790
Reputation: 104
Have a look to question : Get process executed by MONO on GNU/Linux
The solution Looks for all processes names MONO or CLI and then reads the commandline of the process. The commandline provides the name of the application executed by MONO
Get process executed by MONO on GNU/Linux
Cheers
Upvotes: 0
Reputation: 11063
After testing some code and using:
Proccess[] Proc =Process.GetProcessesByName("mono");
I finally reached an exception with his 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
The request feature is not implemented. So it is not possible to recover mono children processes using the .NET framework. I am doing it by using a shell command:
Process.Start("/bin/bash"," -c 'ps -aux | grep Watcher'");
Upvotes: 0
Reputation: 89
Process.GetProcessesbyName internally calls Process.GetProcesses(".") and then filters the results to those matching the requested processName
The problem is that the process is named "mono" not "watcher"...
You'll never find the process by name using "watcher". You'll have to get ProcessesByName("mono").
Upvotes: 1
Reputation: 58762
Try using Process.GetProcessesByName("Watcher")
, that seems to work for me.
Upvotes: 0