Linux查看程序端口占用情况
Linux查看程序端口占用情况
首先使用netstat命令查看其占用的端口:
netstat -anp | grep 9082 tcp6 0 0 :::9082 :::* LISTEN 14155/java
查到进程id之后,用ps命令查看进程的详情:
ps -ef | grep 14155 root 14155 1 0 10月30 ? 00:59:48 /usr/java/bin/java -Djava.util.logging.config.file=/usr/local/demo/apache-tomcat-7.0.77/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M -Djava.endorsed.dirs=/usr/local/demo/apache-tomcat-7.0.77/endorsed -classpath /usr/local/demo/apache-tomcat-7.0.77/bin/bootstrap.jar:/usr/local/demo/apache-tomcat-7.0.77/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/demo/apache-tomcat-7.0.77 -Dcatalina.home=/usr/local/demo/apache-tomcat-7.0.77 -Djava.io.tmpdir=/usr/local/demo/apache-tomcat-7.0.77/temp org.apache.catalina.startup.Bootstrap start root 19552 9347 0 11:13 pts/0 00:00:00 grep 14155
或者 ps -aux | grep 14155
root 14155 0.1 2.1 4758652 341376 ? Sl 10月30 59:48 /usr/java/bin/java -Djava.util.logging.config.file=/usr/local/demo/apache-tomcat-7.0.77/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M -Djava.endorsed.dirs=/usr/local/demo/apache-tomcat-7.0.77/endorsed -classpath /usr/local/demo/apache-tomcat-7.0.77/bin/bootstrap.jar:/usr/local/demo/apache-tomcat-7.0.77/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/demo/apache-tomcat-7.0.77 -Dcatalina.home=/usr/local/demo/apache-tomcat-7.0.77 -Djava.io.tmpdir=/usr/local/demo/apache-tomcat-7.0.77/temp org.apache.catalina.startup.Bootstrap start root 19585 0.0 0.0 112720 952 pts/0 R+ 11:13 0:00 grep 14155
可以看到,9092端口是被14155(进程编号)的进程所占用了,下面我们来关闭这个进程。
kill -9 14155