# Kill process trees listening on given ports. Default: :3000 frontend / :3001 backend. # Called by stop.bat; or: powershell -File stop.ps1 param( [int[]]$Ports = @(3000, 3001) ) $ErrorActionPreference = 'SilentlyContinue' [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 Write-Host "Stopping listeners on :3000 / :3001 (process trees)..." Write-Host "" foreach ($port in $Ports) { $pids = @( Get-NetTCPConnection -LocalPort $port -State Listen | Select-Object -ExpandProperty OwningProcess -Unique ) if (-not $pids -or $pids.Count -eq 0) { Write-Host " :$port idle" continue } foreach ($procId in $pids) { if ($procId -le 0) { continue } Write-Host " :$port -> PID $procId (tree)" & taskkill.exe /T /F /PID $procId | Out-Null } } Write-Host "" Write-Host "Port cleanup finished."