Linux下通过端口号查询占用的进程,并知道其所在的位置

比如要查询2181端口。

1、查询端口占用的进程ID

netstat -anp | grep 2181
tcp6       0      0 :::2181                 :::*                    LISTEN      10997/java 

2181为端口号

10997为PID

还可以使用:

lsof -i:2181
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    10997  jim   25u  IPv6 197822      0t0  TCP *:2181 (LISTEN)

2、根据PID查询所在进程位置

ps -ef | grep 10997
jim      10997  1959  0 12月14 pts/2  00:00:00 /usr/lib/jvm/java-8-oracle/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/jim/opt/zookeeper-3.4.9/bin/../build/classes:/home/jim/opt/zookeeper-3.4.9/bin/../build/lib/*.jar:/home/jim/opt/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/jim/opt/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/home/jim/opt/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/home/jim/opt/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/home/jim/opt/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/home/jim/opt/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/home/jim/opt/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/home/jim/opt/zookeeper-3.4.9/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/jim/opt/zookeeper-3.4.9/bin/../conf/zoo.cfg

 

参考:

http://blog.csdn.net/rocklee/article/details/50886739

http://blog.csdn.net/zhongweijian/article/details/7942611

 

posted @ 2017-12-15 00:09  EasonJim  阅读(860)  评论(0编辑  收藏  举报