# rig45_down.ps1 -- tear down ONLY the PIDs rig45_up.ps1 recorded. # Deliberately does NOT use Get-Process -Name / Stop-Process by name: a blanket # name kill once destroyed a live tester session. If a PID has been recycled to # a different image, it is skipped. $ErrorActionPreference = 'Continue' $scratch = 'C:\Users\EPILECTRIK\AppData\Local\Temp\claude\C--git-bt411\89ab96e9-6cf0-4555-939d-05bf3708745a\scratchpad' $pidfile = Join-Path $scratch 'rig45_pids.txt' if (-not (Test-Path $pidfile)) { "no pidfile -- nothing recorded, nothing killed"; exit 0 } # The console is launched with output redirection, so Start-Process wraps it in a # cmd.exe shim (-> python.bat -> python). Kill the recorded PID *and its children*, # still strictly by PID and only for the images this rig is known to launch. $targets = @() foreach ($line in Get-Content $pidfile) { $procId = 0 if (-not [int]::TryParse($line.Trim(), [ref]$procId)) { continue } $targets += @(Get-CimInstance Win32_Process -Filter "ParentProcessId=$procId" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty ProcessId) $targets += $procId } foreach ($procId in ($targets | Select-Object -Unique)) { $p = Get-Process -Id $procId -ErrorAction SilentlyContinue if (-not $p) { "pid $procId already gone"; continue } # Only kill it if it is still one of the images this rig launches. if ($p.ProcessName -notin @('btl4','python','cmd','conhost')) { "pid $procId is now '$($p.ProcessName)' -- PID recycled, SKIPPING" continue } Stop-Process -Id $procId -Confirm:$false -ErrorAction SilentlyContinue Start-Sleep -Milliseconds 300 if (Get-Process -Id $procId -ErrorAction SilentlyContinue) { "pid $procId ($($p.ProcessName)) DID NOT DIE" } else { "killed pid $procId ($($p.ProcessName))" } } Remove-Item $pidfile -ErrorAction SilentlyContinue "teardown complete"