TL;DR
Three steps: ss -tlnp to list listeners, lsof -i :PORT to find the owner, ps -p PID -o pid,cmd to confirm before kill.
List Listeners
| Action | Command |
|---|
| All TCP listeners with processes | ss -tlnp |
| Filter by port | ss -tlnp 'sport = :8080' |
| Legacy | netstat -tlnp |
| UDP | ss -ulnp |
Find Processes
| Action | Command |
|---|
| Who owns the port | lsof -i :8080 |
| Find by name | pgrep -f keyword |
| Process details | ps -p PID -o pid,user,cmd |
| Filter ps output | `ps aux | grep keyword` |
Handle Processes
| Action | Command |
|---|
| Graceful kill | kill PID |
| Force kill | kill -9 PID |
| Kill by name | pkill -f keyword |
Tips
- 127.0.0.1 = localhost only; 0.0.0.0 /
* = exposed. - Missing process names in
ss usually means missing privileges; use sudo. - Verify PID mapping before killing.
Sources
- Linux man pages (ss / lsof / ps / kill)
最后更新:2026-08-02