按端口终止进程。
优雅至极。

一个极速 CLI,可查找并终止占用端口的进程。交互式 TUI、监视模式、进程树,零依赖。

npm 下载量 (opens in new tab) GitHub 星标 (opens in new tab)
0 零依赖
0 支持平台
0+ 测试通过
0 语言支持

为什么选择 slay?

回收端口所需的一切。

交互式 TUI

使用键盘导航搜索、浏览和多选进程。

slay -i

终止动画

当进程被终止时,观看子弹飞过终端。

slay 3000

优雅关闭

先发送 SIGTERM,仅在进程拒绝退出时才升级为 SIGKILL。

slay -g 3000

监视模式

持续轮询并自动终止在端口上重生的进程。

slay -w 3000

进程树

终止整个进程树,先终止子进程,确保干净退出。

slay --tree 3000

JSON 输出

将 NDJSON 管道传输到 jq,用于脚本编写、CI 流水线和自动化。

slay --json 3000

智能标签

自动识别 Node、Python、Docker、PostgreSQL、Vite 等 20 多种进程。

slay --all

零依赖

无臃肿。仅包含所需内容。一秒内完成安装。

npm i -g slay-port

跨平台

支持 macOS (lsof)、Linux (lsof) 和 Windows (netstat + taskkill)。

works everywhere ✓

配置预设

将端口组合保存为命名配置。运行 slay --profile dev。

slay --profile dev

端口范围

使用 slay 8000-8010 终止端口范围。

slay 8000-8010

端口信息

无需终止即可检查端口。查看 PID、CPU、内存和运行时间。

slay info 3000

Shell 自动补全

在 bash、zsh 和 fish 中自动补全命令、参数和配置名称。

slay completions zsh

按名称终止

通过进程名称定位,支持正则表达式。批量操作时可排除特定进程。

slay --name "node.*"

终止后钩子

终止进程后自动执行命令 — 重启服务、触发构建或通知团队。

slay 3000 --then "npm start"

端口可用性

检查端口是否空闲,查找下一个可用端口。适用于 CI 脚本和自动化。

slay check 3000

告别 猜测 PID

旧方式很痛苦。slay 只需一条命令。

旧方式

bash
$ lsof -iTCP:3000 -sTCP:LISTEN
node 12847 user 23u IPv4 TCP *:3000
$ kill -9 12847
$ lsof -iTCP:3000 -sTCP:LISTEN
# still alive... try again?
$ kill -SIGKILL 12847

slay 方式

slay
$ slay 3000
3000 > node PID 12847 (Dev Server)
killed PID 12847 on port 3000 [SIGKILL]
 
Done in 0.2s
 

快速 开始

一条命令即可启动运行。

快速开始
npx slay-port 3000
全局安装
npm i -g slay-port && slay 3000
快速开始
pnpm dlx slay-port 3000
全局安装
pnpm add -g slay-port && slay 3000
快速开始
yarn dlx slay-port 3000
全局安装
yarn global add slay-port && slay 3000
快速开始
bunx slay-port 3000
全局安装
bun add -g slay-port && slay 3000
快速开始
brew install hammadxcm/slay/slay-port
全局安装
brew install hammadxcm/slay/slay-port && slay 3000
快速开始
sudo snap install slay-it --classic
全局安装
sudo snap install slay-it --classic && slay 3000
快速开始
sudo apt install slay-port
全局安装
sudo apt install slay-port && slay 3000
快速开始
scoop bucket add slay https://github.com/hammadxcm/scoop-slay && scoop install slay
全局安装
scoop install slay && slay 3000
快速开始
winget install hammadxcm.slay-port
全局安装
winget install hammadxcm.slay-port && slay 3000
API 用法
import { findByPort, killProcess } from 'slay-port'

查看 实际效果

十五种终止方式。

Basic Kill

slay 3000
$ slay 3000
3000 > node PID 12847 (Dev Server)
* *
***
killed PID 12847 on port 3000 [SIGKILL]

Interactive Mode

slay -i
$ slay -i
> 3000 node PID 12847 Dev Server
8080 python PID 9321 HTTP Alt
5432 pg PID 4510 PostgreSQL
↑↓ navigate space select enter confirm

Watch Mode

slay 3000 -w
$ slay 3000 -w
watching port 3000...
killed PID 12847 [SIGKILL]
watching port 3000...
process respawned as PID 12901
killed PID 12901 [SIGKILL]
watching port 3000...

Force Kill

slay 3000 -f
$ slay 3000 -f
3000 > node PID 12847 (Dev Server)
*========================***
killed PID 12847 on port 3000 [SIGKILL]
no confirmation needed (-f)

Graceful Shutdown

slay 3000 --soft
$ slay 3000 --soft
3000 > node PID 12847 (Dev Server)
sending SIGTERM...
waiting for graceful exit (5s)...
process exited gracefully [SIGTERM]

Multi-port

slay 3000 8080 5432
$ slay 3000 8080 5432
3000 > node PID 12847 (Dev Server)
8080 > python PID 9321 (HTTP Alt)
5432 > pg PID 4510 (PostgreSQL)
killed 3 processes on 3 ports

Dry Run

slay 3000 -n
$ slay 3000 -n
3000 > node PID 12847 (Dev Server)
[dry run] would kill PID 12847
no processes were harmed

Process Tree

slay 3000 -t
$ slay 3000 -t
3000 > node PID 12847 (Dev Server)
└─ PID 12848 (worker)
└─ PID 12849 (worker)
killed tree: 12849, 12848, 12847

Kill by Name

slay --name "node.*"
$ slay --name "node.*" --exclude "vite"
PID 12847 node server.js (port 3000)
PID 13201 node worker.js (port 3001)
PID 14500 node vite.js (excluded)
killed 2 processes, 1 excluded

Post-Kill Hook

slay 3000 --then "npm start"
$ slay 3000 --then "npm start"
3000 > node PID 12847 (Dev Server)
killed PID 12847 on port 3000 [SIGKILL]
running hook: npm start
hook completed (exit 0)

Port Check

slay check 3000
$ slay check 3000
port 3000 is in use (node PID 12847)
$ slay check --next 3000
port 3002 is available

Init Config

slay init
$ slay init
✓ Created .slay.json with example profiles

Run Profile

slay --profile dev
$ slay --profile dev
3000 > node PID 12847 (Dev Server)
5173 > node PID 13201 (Vite)
5432 > pg PID 4510 (PostgreSQL)
killed 3 processes on 3 ports

Port Range

slay 8000-8005
$ slay 8000-8005
8000 > node PID 9001 (HTTP Alt)
8001 > node PID 9002 (HTTP Alt)
killed 2 processes on 2 ports (4 ports clear)

JSON Output

slay 3000 --json
$ slay 3000 --json
{"type":"found","pid":12847,"port":3000}
{"type":"killed","pid":12847,"signal":"SIGKILL"}
{"type":"summary","killed":1,"failed":0}

UDP Ports

slay 53 --udp
$ slay 53 --udp
53/udp > mDNSResponder PID 289
*========================***
killed PID 289 on port 53/udp [SIGKILL]

All Listeners

slay --all -y
$ slay --all -y
scanning all ports...
found 5 listening processes
killed 5/5 processes
0 failed

Verbose Mode

slay 3000 -v
$ slay 3000 -v
[tcp] 3000 > node PID 12847
[signal] sending SIGKILL to 12847
[timing] kill took 12ms
killed PID 12847 on port 3000 [SIGKILL]

编程式 API

在你的 Node.js 项目中将 slay 作为库使用。

导出

  • findByPort(platform, port) Find processes on a specific port
  • findByPorts(platform, ports) Find processes on multiple ports
  • findAllListening(platform) Find all listening processes
  • killProcess(platform, proc) Kill a single process
  • killAll(platform, procs) Kill multiple processes
  • enrichLabel(proc) Add smart labels to a process
api.ts
import { findByPort, killProcess, platform }
from 'slay-port';
 
const procs = await findByPort(platform, 3000);
 
for (const proc of procs) {
const result = await killProcess(platform, proc);
console.log( `Killed $${result.pid} on $${result.port}` );
}