chore(dev): 按端口杀进程树,避免 Windows 孤儿监听
新增 stop.bat/ps1/sh,并写入本地开发规则:停服务用脚本、停后复核端口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
24
stop.ps1
Normal file
24
stop.ps1
Normal file
@@ -0,0 +1,24 @@
|
||||
# 按 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user