You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Diagnostics.Process.ProcessName returning incorrect information on Linux with .NET 5 #33673
We have tests that expect the pwsh process to have a ProcessName of pwsh, but on Linux, the name is actually ConsoleHost mai (looks to be cut off). Works correctly on Windows and macOS.
Note that [System.AppDomain]::CurrentDomain.FriendlyName returns pwsh as expected.
Let me investigate this a bit after my meeting, wrote a simple C# program and it doesn't repro. The only change on the PowerShell side was moving from .NET Core 3.1 to .NET 5 preview.1
Seems reasonable, @tmds. Might be a good idea to also mention in the docs that in some platforms the name might be truncated due to platform limitations (as mentioned by @SteveL-MSFT) to avoid surprises.
Although, to determine the ProcessName, maybe we could try using getauxval(AT_EXECFN)? That shouldn't be affected by the thread name.
Maybe we should continue to no-op for changing name of the main thread?
I'll make a PR for this change.
Although, to determine the ProcessName, maybe we could try using getauxval(AT_EXECFN)?
I was not aware of this API. We want to get this info for any process on the system. This is available in /proc under an auxv file. Unfortunately, it includes the pointer to the string, which isn't directly usable.
Activity
tmds commentedon Mar 17, 2020
@SteveL-MSFT do you have some info on how to reproduce this?
Program.cs:
outputs:
using:
SteveL-MSFT commentedon Mar 17, 2020
So in PowerShell, the code is calling
GetProcessById()tmds commentedon Mar 17, 2020
also outputs:
SteveL-MSFT commentedon Mar 17, 2020
Let me investigate this a bit after my meeting, wrote a simple C# program and it doesn't repro. The only change on the PowerShell side was moving from .NET Core 3.1 to .NET 5 preview.1
SteveL-MSFT commentedon Mar 17, 2020
@tmds, ok, the problem is when Thread.CurrentThread.Name is set, then the process name uses that:
tmds commentedon Mar 17, 2020
In dotnet/coreclr#27182 support was added for naming Linux threads.
The implementation is using
pthread_setname_np.The name set for the main thread shows up in the
commfield in/proc/<pid>/stat(see http://man7.org/linux/man-pages/man5/proc.5.html) which we use to determine the ProcessName.Previously changing the thread name was a no-op.
Maybe we should continue to no-op for changing name of the main thread?
cc @janvorli @lpereira
janvorli commentedon Mar 17, 2020
@tmds I agree.
lpereira commentedon Mar 17, 2020
Seems reasonable, @tmds. Might be a good idea to also mention in the docs that in some platforms the name might be truncated due to platform limitations (as mentioned by @SteveL-MSFT) to avoid surprises.
Although, to determine the
ProcessName, maybe we could try usinggetauxval(AT_EXECFN)? That shouldn't be affected by the thread name.tmds commentedon Mar 21, 2020
I'll make a PR for this change.
I was not aware of this API. We want to get this info for any process on the system. This is available in
/procunder anauxvfile. Unfortunately, it includes the pointer to the string, which isn't directly usable.Ensure Process.ProcessName doesn't change when setting Thread.Name on…