$root = Split-Path -Parent $PSScriptRoot $pidDir = Join-Path $root "local_static\pids" foreach ($Port in @(80, 8000)) { $pidFile = Join-Path $pidDir "http_$Port.pid" if (-not (Test-Path $pidFile)) { Write-Host "[skip] port $Port no pid file" continue } $oldPid = [int](Get-Content $pidFile -ErrorAction SilentlyContinue) if ($oldPid -gt 0) { $proc = Get-Process -Id $oldPid -ErrorAction SilentlyContinue if ($proc) { Stop-Process -Id $oldPid -Force -ErrorAction SilentlyContinue Write-Host "[stop] port $Port pid $oldPid" } else { Write-Host "[skip] port $Port pid $oldPid not running" } } Remove-Item $pidFile -Force -ErrorAction SilentlyContinue }