当前位置:首页 > linux > 正文

linux 端口被哪个进程占用

  • linux
  • 2024-04-30 23:39:13
  • 3513

1. 使用 netstat 命令
shell
netstat -tulpn
此命令将显示所有正在运行的进程以及他们正在监听的端口。 使用 grep 命令过滤特定端口:
shell
netstat -tulpn | grep :PORT_NUMBER
2. 使用 lsof 命令
shell
lsof -i :PORT_NUMBER
此命令将显示正在监听或使用指定端口的文件描述符。
3. 使用 ss 命令
shell
ss -tulpn | grep :PORT_NUMBER
此命令类似于 netstat,但它显示了更详细的信息,包括每个端口的套接字状态。
4. 使用 top 命令
shell
top -n 1 | grep PORT_NUMBER
此命令将显示正在占用指定端口的进程的 CPU 和内存使用情况。
5. 使用 fuser 命令
shell
fuser -n tcp PORT_NUMBER
此命令将显示由特定端口占用的文件描述符的 PID。
示例
确定占用端口 80 的进程:
shell
netstat -tulpn | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 19191/nginx
此输出显示 nginx 进程 (PID 为 19191) 正在监听端口 80。