From 141da816abc0788a06ae5a73a09fb4f54a79c8aa Mon Sep 17 00:00:00 2001 From: Flavien MICHALECZEK Date: Tue, 4 Feb 2025 13:07:01 +0100 Subject: [PATCH] Use Environment.ProcessId in SpecialVariables.PID (#24926) --- src/System.Management.Automation/engine/SessionState.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index e65f65ff38..2ed9612f49 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -337,10 +337,9 @@ namespace System.Management.Automation this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PID - Process currentProcess = Process.GetCurrentProcess(); v = new PSVariable( SpecialVariables.PID, - currentProcess.Id, + Environment.ProcessId, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PIDDescription); this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);