查看Linux某端口被哪个进程占用

例如:

nginx: [emerg] bind() to 0.0.0.0:8004 failed (98: Address already in use) 1.查看占用8004端口的进程ID:
$ netstat -anp |grep 8004
tcp  0  0 0.0.0.0:8004  0.0.0.0:*  LISTEN  2768/nginx.conf
2.查看进程信息:
$ ps -u -p 2768
USER  PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND

mars 2768  0.0  0.5 385344 353712 ?     Ss   Mar28   0:00 nginx: master process /home/mars/nginx/sbin/nginx -p/home/mars/nginx -c /home/

3.根据实际情况修改端口或停止原进程

Linux netstat命令详解

简介

Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。

输出信息含义

执行netstat后,其输出结果为

Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 2 210.34.6.89:telnet 210.34.6.96:2873 ESTABLISHED tcp 296 0 210.34.6.89:1165 210.34.6.84:netbios-ssn ESTABLISHED tcp 0 0 localhost.localdom:9001 localhost.localdom:1162 ESTABLISHED tcp 0 0 localhost.localdom:1162 localhost.localdom:9001 ESTABLISHED tcp 0 80 210.34.6.89:1161 210.34.6.10:netbios-ssn

阅读全文