Which process has that port open? (Linux / netstat -anp)
by Colin on Dec.21, 2010, under General, Linux
Occasionally, I’ll have an application that I’m working on die spectacularly and still hold on to the open sockets / ports. in Java you would see the java.net.BindException: Address already in use for an open port much like:
java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
...
It took me a second to figure out how locate the process, but it turned out to be a really easy task using the netstat command by executing ‘netstat -anp | grep 8080‘ (a = all interfaces, n = numeric, p = show pid) This isn’t perfect since it will still show you anything with a pid of 8080 (the port number I was looking for), but its a great quick-and dirtry way to identify the process. and once I’ve found it I can kill it with a ‘kill -9 <pid>‘
user@machine:~/$ netstat -anp | grep 8080
tcp6Â Â Â Â Â Â 0Â Â Â Â Â 0 :::8080Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â :::*Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LISTENÂ Â Â Â Â 19884/java
user@machine:~/$ kill -9 19884
Which reminds me of this classic (please excuse the profanity):
ps:
Windows => netstat -ano
OSX => lsof -i -P
May 18th, 2011 on 10:04 am
Nice and easy though, i killed a task which i need it was a console inside it that was the problem :/
ahwell we all learn from our mistakes