Files
jiang13-bbs/stop.ps1
freefire 5052bcd805 chore(dev): 按端口杀进程树,避免 Windows 孤儿监听
新增 stop.bat/ps1/sh,并写入本地开发规则:停服务用脚本、停后复核端口。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 07:27:45 +08:00

25 lines
677 B
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 按 Listen 端口终止进程树(含子进程)。默认 :3000 前端 / :3001 后端。
# 由 stop.bat 调用;也可直接:powershell -File stop.ps1
param(
[int[]]$Ports = @(3000, 3001)
)
$ErrorActionPreference = 'SilentlyContinue'
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 空闲"
continue
}
foreach ($procId in $pids) {
if ($procId -le 0) { continue }
Write-Host " :$port -> PID $procId (含子进程)"
& taskkill.exe /T /F /PID $procId | Out-Null
}
}