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
Proposal: Add new property for getting process command line, environment and parent process #21941
When writing tools, it is often useful to be able to get to information about the processes you manage.
This is easy on Linux with /proc, but harder on windows.
When getting parent process, it is important to check the start time of the process with the PID of the queried process to see if it is older to prevent errors when process ids are recycled.
We could use this in MSBuild. We attempt to find worker processes to connect to by enumerating running MSBuild processes and then trying to connect to them.
On Windows + full framework, this is done with Process.GetProcessesByName("MSBuild"), but on core (any OS) the process name tends to be the host . . . so we'll have to try to connect to every dotnet process, instead of filtering to only ones that are running MSBuild. If we had access to the command line, we could be smarter in both cases by attempting to connect only to processes started with the background-process command line parameters.
changed the title [-]Proposal: Add new property for getting process command line and environment and parent process[/-][+]Proposal: Add new property for getting process command line,environment and parent process[/+]on Jan 18, 2018
changed the title [-]Proposal: Add new property for getting process command line,environment and parent process[/-][+]Proposal: Add new property for getting process command line, environment and parent process[/+]on Jan 18, 2018
I think a string is better. There may be many nuances to how a command line is split into it's parts, and I think that should be left to some higher level.
@joeloff asked today about getting parent process ID, for an installer scenario. I suppose the argument for returning a Process object vs GetProcessById() is to avoid races with pid recycling.
I wonder whether it would help to consider environment, command line, and parent as separate requests.
Activity
rainersigwald commentedon Jan 12, 2018
We could use this in MSBuild. We attempt to find worker processes to connect to by enumerating running MSBuild processes and then trying to connect to them.
On Windows + full framework, this is done with
Process.GetProcessesByName("MSBuild"), but on core (any OS) the process name tends to be the host . . . so we'll have to try to connect to everydotnetprocess, instead of filtering to only ones that are running MSBuild. If we had access to the command line, we could be smarter in both cases by attempting to connect only to processes started with the background-process command line parameters.[-]Proposal: Add new property for getting process command line and environment and parent process[/-][+]Proposal: Add new property for getting process command line,environment and parent process[/+][-]Proposal: Add new property for getting process command line,environment and parent process[/-][+]Proposal: Add new property for getting process command line, environment and parent process[/+]jnm2 commentedon Feb 13, 2018
IReadOnlyDictionary?powercode commentedon Feb 13, 2018
I think a
stringis better. There may be many nuances to how a command line is split into it's parts, and I think that should be left to some higher level.jnm2 commentedon Feb 13, 2018
Unless you're not on Windows. Then to get a single string you have to join the native process args, so you lose information.
powercode commentedon Feb 13, 2018
In that case, we should be able to do the same thing on windows as .net executables do to get the
string[] argsin theMainfunction.powercode commentedon Feb 13, 2018
Oh, now I understand that we may be talking about the environment. And in that case
IReadOnlyDictionaryseams reasonable.jnm2 commentedon Feb 13, 2018
Ah, sorry! Yes,
IReadOnlyDictionary<string, string>for the environment.stringfor the command line works well on Windows but what about other operating systems? Do we want two properties like is being added for ProcessStartInfo (https://github.com/dotnet/corefx/issues/23592)?powercode commentedon Feb 13, 2018
it is a string in
/proc/CJHarmath commentedon Sep 12, 2018
This would also fix PowerShell Get-Process missing the command line argument
PowerShell/PowerShell#1849
danmoseley commentedon Sep 2, 2021
@joeloff asked today about getting parent process ID, for an installer scenario. I suppose the argument for returning a Process object vs GetProcessById() is to avoid races with pid recycling.
I wonder whether it would help to consider environment, command line, and parent as separate requests.
alexey-leonovich commentedon Mar 5, 2026
I'm still interested in this improvement.
powercode commentedon Mar 5, 2026
So am I