Linux下通过进程名查询占用的端口

1、首先根据名称用ps命令查看进程ID:

ps -ef | grep zookeeper    
jim      10997  1959  0 12月14 pts/2  00:00:01 /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

10997为进程ID

后面是启动路径和对应的进程名

1.1、对于在Java虚拟机中运行的进程,比如tomcat的守护进程,可以直接用jsp命令查看:

jps -l | grep zookeeper
10997 org.apache.zookeeper.server.quorum.QuorumPeerMain

已经知道进程的确切名称,可以用pidof查看: 

pidof Name    

不过这个一般少用,因为真的很难查 

2、查到进程ID之后,使用netstat命令查看其占用的端口:

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

红色的为占用的端口,LISTEN为占用的类型,绿色粗体为进程ID

参考:

http://blog.csdn.net/zsg88/article/details/76359347

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注