Install
openclaw skills install port-process通过端口查找和管理系统进程。支持查找占用端口的进程、杀掉占用端口的进程、查看端口使用情况等操作。适用于 macOS 和 Linux 系统。使用场景:(1) "谁占用了 8080 端口",(2) "杀掉占用 3000 端口的进程",(3) "查看当前端口使用情况"。
openclaw skills install port-process通过端口查找和管理系统进程的工具集。支持跨平台(macOS/Linux)操作。
# 方法一:使用 lsof(macOS/Linux)
lsof -ti :8080
# 方法二:使用 netstat(Linux)
netstat -tulpn | grep :8080
# 方法三:使用 ss(现代 Linux)
ss -tulpn | grep :8080
# 一键杀掉占用 8080 端口的进程
lsof -ti :8080 | xargs kill -9
# 或者使用提供的脚本
python3 scripts/kill_by_port.py 8080
查找单个端口:
lsof -i :8080
查找多个端口:
lsof -i :8080 -i :3000
显示进程详细信息:
lsof -ti :8080 | xargs ps -fp
安全终止(先尝试 SIGTERM):
lsof -ti :8080 | xargs kill -15
强制终止(SIGKILL):
lsof -ti :8080 | xargs kill -9
使用脚本安全终止:
python3 scripts/kill_by_port.py 8080 --safe
查看所有监听端口:
# macOS
lsof -i -P | grep LISTEN
# Linux
netstat -tulpn
ss -tulpn
查看特定用户的端口占用:
lsof -i -u username
通过端口终止进程的安全脚本。
用法:
# 强制终止
python3 scripts/kill_by_port.py 8080
# 安全终止(先 SIGTERM,等待后再 SIGKILL)
python3 scripts/kill_by_port.py 8080 --safe
# 仅查看,不终止
python3 scripts/kill_by_port.py 8080 --dry-run
查找占用端口的进程信息。
用法:
# 查找单个端口
python3 scripts/find_port.py 8080
# 查找多个端口
python3 scripts/find_port.py 8080 3000 5432
# 输出 JSON 格式
python3 scripts/find_port.py 8080 --json
列出所有正在使用的端口。
用法:
# 列出所有监听端口
python3 scripts/list_ports.py
# 仅显示 TCP 端口
python3 scripts/list_ports.py --tcp
# 仅显示 UDP 端口
python3 scripts/list_ports.py --udp
# 显示详细信息
python3 scripts/list_ports.py --verbose
lsof 作为主要工具netstat 作为备选ss 作为首选(现代系统)netstat 作为备选lsof# 杀掉占用前端开发服务器端口的进程
python3 scripts/kill_by_port.py 3000
# 杀掉占用后端 API 端口的进程
python3 scripts/kill_by_port.py 8000
# 杀掉占用数据库端口的进程
python3 scripts/kill_by_port.py 5432
# 查看是谁占用了端口
python3 scripts/find_port.py 8080
# 查看所有端口使用情况
python3 scripts/list_ports.py --verbose
# 在启动服务前清理端口
python3 scripts/kill_by_port.py 8080 --dry-run || true
python3 scripts/kill_by_port.py 8080
./start-my-server.sh
--dry-run 或先运行 find_port.py 确认要终止的进程--safe 选项给进程优雅退出的机会sudo apt install lsof (Debian/Ubuntu) 或 sudo yum install lsof (RHEL/CentOS)netstat -an | grep TIME_WAITsudo 运行以查看其他用户的进程sudo kill 时要格外小心