Skip to content
Advertisement

Workaround for bug in mono: Wrong Process.ProcessName

If you work with mono and use Process.ProcessName you may get wrong results on some computers.

For example instead of the process name “kwrite” you may get “kdeinit4” (seen on SUSE).

On Ubuntu I have even seen complete bullshit like “kdeinit4;5535948c (deleted)” instead of “kwrite“.

Note: On other computers the result may be correct.

If I use Process.MainModule.ModuleName it retruns the same wrong name. And if I use Process.MainModule.FileName it gives the wrong path. Apart from that these commands are EXTREMELY slow.

So whatever I try it is full of bugs. What can I do?

Advertisement

Answer

The workaround can be done with two lines:

String sProcFile = String.Format("/proc/{0}/comm", proc.Id);
String sProcName = File.ReadAllText(sProcFile).Trim();

It works like a charm on all computers where ProcessName fails.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement