- 首先通过端口号查询pid, 然后通过pid查询进程
通过port查pid
lsof -i:port // lsof -i:8080 // 通过端口获取pid
ps -ef |grep pid // 查看进程
netstat -nap|grep port
ll /proc/pid/cwd // 查看服务目录
netstat -nap|grep pid // 通过pid查询端口号
#netstat -nap|grep 8788
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8788 0.0.0.0:* LISTEN 11651/java
# lsof -i:8788
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 11651 guest 45u IPv4 3536290374 0t0 TCP *:8788 (LISTEN)
# ps -ef|grep 11651
guest 11651 5912 7 10:25 ? 00:29:29 /usr/local/java/jdk1.8.0_201/bin/java -jar demo-3.0.0.10-release.jar --spring.profiles.active=prd
guest 28844 25993 0 17:20 pts/0 00:00:00 grep --color=auto 11651
# ll /proc/11651/cwd
lrwxrwxrwx 1 demo gou 0 Apr 12 10:25 /proc/11651/cwd -> /data/demo/demo_api
]$ netstat -nap|grep 11651
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8781 0.0.0.0:* LISTEN 11651/java
tcp 32 0 172.116.42.25:44508 117.81.33.175:8743 CLOSE_WAIT 11651/java
tcp 0 0 172.116.42.25:54118 172.16.6.58:6379 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:57874 172.16.49.140:3306 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:47998 172.16.49.140:3306 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:55972 172.16.6.58:6379 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:51352 172.16.1.5:3306 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:55974 172.16.26.8:6379 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:57698 172.16.26.58:6379 ESTABLISHED 11651/java
tcp 32 0 172.116.42.25:41702 47.111.51.31:443 CLOSE_WAIT 11651/java
tcp 0 0 172.116.42.25:54594 172.16.6.58:6379 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:54592 172.16.6.58:6379 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:55970 172.16.6.58:6379 ESTABLISHED 11651/java
tcp 0 0 172.116.42.25:48002 172.16.49.40:3306 ESTABLISHED 11651/java
unix 2 [ ] STREAM CONNECTED 3536288174 11651/java
unix 2 [ ] STREAM CONNECTED 3536289162 11651/java
网友评论