Workaround for bug in mono: Wrong Process.ProcessName

…衆ロ難τιáo~ 提交于 2020-01-05 06:29:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29827331/workaround-for-bug-in-mono-wrong-process-processname

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!