본문 바로가기
tip

8080 already in use

by [김경민]™ ┌(  ̄∇ ̄)┘™ 2013. 8. 26.
728x90

[출처] http://java-monitor.com/forum/showthread.php?t=22


On FreeBSD:

Code:
% sockstat -4 -p 8080
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
kjkoster java       80929 31 tcp4   *:8080                *:*
On Mac OS X:
Code:
% lsof -i TCP:8080
COMMAND   PID     USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
java    37801 kjkoster   11u  IPv6 0xa8c44bc      0t0  TCP *:http-alt (LISTEN)
On Linux (thanks to MHSL on FreeNode's IRC channel #tomcat):
Code:
% netstat -anp | grep 8080
Proto Recv-Q Send-Q Local Address          Foreign Address        State      PID/Program name
tcp        0      0 127.0.0.1:8080        0.0.0.0:*              LISTEN      1501/jsvc.exec
On Windows, you can do it as described in this tutorial.

This gives us the process ID of the process that is bound to port 8080. They are shown in bold in the above examples.

Given this process ID we can examine the process in more detail using the command ps. Again, the precise syntax is OS-dependent.

On FreeBSD:
Code:
% ps -wwp 80929
  PID  TT  STAT      TIME COMMAND
80929  p1  I+     0:04.61 /usr/local/jdk1.6.0/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/usr/home/kjkoster/apache-tomcat-6.0.16/conf/logging.properties -Djava.endorsed.dirs=/usr/home/kjkoster/apache-tomcat-6.0.16/endorsed -classpath :/usr/home/kjkoster/apache-tomcat-6.0.16/bin/bootstrap.jar -Dcatalina.base=/usr/home/kjkoster/apache-tomcat-6.0.16 -Dcatalina.home=/usr/home/kjkoster/apache-tomcat-6.0.16 -Djava.io.tmpdir=/usr/home/kjkoster/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start
On Mac OS X:
Code:
% ps -wwp 37801
  PID TTY           TIME CMD
37801 ttys000    0:04.33 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/Users/kjkoster/Downloads/apache-tomcat-6.0.16/conf/logging.properties -Djava.endorsed.dirs=/Users/kjkoster/Downloads/apache-tomcat-6.0.16/endorsed -classpath :/Users/kjkoster/Downloads/apache-tomcat-6.0.16/bin/bootstrap.jar -Dcatalina.base=/Users/kjkoster/Downloads/apache-tomcat-6.0.16 -Dcatalina.home=/Users/kjkoster/Downloads/apache-tomcat-6.0.16 -Djava.io.tmpdir=/Users/kjkoster/Downloads/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start
On Linux:
Code:
% ps -fp PID
UID        PID  PPID  C STIME TTY          TIME CMD
tomcat  1501 1500  1 Jul16 ?        03:29:42 jsvc.exec -home /usr/local/java -jvm server -user tomcat -Djava.endorsed.dirs=/usr/local/apache-tomcat-6/comm
If we are happy that this process is the one that needs killing, use the kill command to end it. This is the same on all operating systems: kill <process id>.

This should help you clear out excess application servers and free up port 8080 to run your own application server on. Don't be afraid to experiment. UNIX protects the processes of other user's on your machine. So if you accidently try to kill a Tomcat from one of your co-workers, you will not do any damage to it. The kill command issues an error message and exits safely.

Earlier I said that process assasination would be faster than rebooting, but up until now you'f probably spend a couple of minutes trying out the commands. Rebooting would have been a lot faster, I'm sure. Let's tie the commands together to form a single command line that can be cut'n-pasted into a terminal.

On FreeBSD the commands tie together as shown below:
Code:
kill `sockstat -4 -p 8080 | awk '/\\*:8080/{print $3}'`
On Max OS X, it looks like this.
Code:
kill `lsof -i TCP:8080 | awk '/LISTEN/{print $2}'`
You get the picture. Constructing the command for you own distribution is left as an exercise to the reader.

728x90

댓글